码迷,mamicode.com
首页 > 移动开发 > 详细

移动端,由页面定位的滚动区域引起光标可以跟页面滑动

时间:2016-11-01 16:39:21      阅读:836      评论:0      收藏:0      [点我收藏+]

标签:bugs   png   测试   http   i++   隐藏   表单   bsp   软键盘   

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 objTextarea = document.getElementsByTagName(‘textarea‘);
        var input = new objBlur(obj);
        //var textarea = new objBlur(objTextarea);
        input=null;
        //textarea = null;
    }
})

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

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

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

移动端,由页面定位的滚动区域引起光标可以跟页面滑动

标签:bugs   png   测试   http   i++   隐藏   表单   bsp   软键盘   

原文地址:http://www.cnblogs.com/q460021417/p/6019905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!