zoukankan      html  css  js  c++  java
  • 移动端,由页面定位的滚动区域引起光标可以跟页面滑动

    var isIPHONE = navigator.userAgent.toUpperCase().indexOf('IPHONE')!= -1;
    
    // 元素失去焦点隐藏iphone的软键盘
    
    function objBlur(obj,time){
        var that;
    //  if(typeof id != 'string') throw new Error('objBlur()参数错误');
            time = time || 100,
            docTouchend = function(event){
                    if(event.target!= obj){
                        setTimeout(function(){
                            if (typeof($(event.target).attr("readonly"))!=="undefined") {
                                obj[that].blur();
                                document.removeEventListener('touchend', docTouchend,false);
                                return false;
                            }
                        },time);
                    }
            };
            if(obj){
                for (var i = 0; i<obj.length; i++) {
                    obj[i].index = i;
                    obj[i].addEventListener('focus', function(){
                        that = this.index;
                        document.addEventListener('touchend', docTouchend,false);
                    },false);
                }
            }else{
                throw new Error('objBlur()没有找到元素');
            }
    }

    调用:

    $(function () {
        if(isIPHONE){
            var obj = document.getElementsByTagName('input');
            var input = new objBlur(obj);
            input=null;
        }
    })

    说明:焦点在某个input元素上,此时快速滑动页面,由于是absolute定位,光标跟不上滚动的速度。导致错位问题。

    解决方案就是在你滑动页面的时候直接让input失去焦点,隐藏光标。这里对测试人员吐槽一下:尼玛,好好的表单你不填,你非要滑动页面玩,XX。。。

    不过话说回来,要不是测试员奇葩,我也不会学到更多东西,嘻嘻!还是非常感谢的!Bugs,come on!!     测试→

  • 相关阅读:
    Oracle数据库安装
    [转]卡西欧手表调日期正确方法
    python密码处理(可用于生产模式)
    [转]python对json的相关操作
    [转]Python中的with…as…
    Python标准库--os模块
    我的github代码添加
    Python正则表达式+自创口诀
    自己总结python用xlrdxlwt读写excel
    CentOS安装+配置+远程
  • 原文地址:https://www.cnblogs.com/q460021417/p/6019905.html
Copyright © 2011-2022 走看看