vue技术栈移动端的bug

ios6在input框输入内容时软键盘弹起来把页面上移后,使页面

2019-08-07  本文已影响16人  小猪_9b2e

解决办法:

// 解决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)

上一篇 下一篇

猜你喜欢

热点阅读