ios6在input框输入内容时软键盘弹起来把页面上移后,使页面卡在ios顶部不会自动下来

解决办法:

// 解决ios上页面上移的bug

            setTimeout(function(){

                if(document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA'){

                    return

                }

                var result = 'pc';

                if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS

                    result = 'ios'

                }else if(/(Android)/i.test(navigator.userAgent)) {  //判断Android

                    result = 'android'

                }

                if( result = 'ios' ){

                    document.activeElement.scrollIntoViewIfNeeded(true);

                    var scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;

                    window.scrollTo(0, Math.max(scrollHeight - 1, 0));

                }

            },10)

你可能感兴趣的:(ios6在input框输入内容时软键盘弹起来把页面上移后,使页面卡在ios顶部不会自动下来)