h5 适配手机


    function tr_setViewport(w) {
        var scale = parseInt(window.screen.width) / w,
            a = /Android (\d+\.\d+)/.test(navigator.userAgent) ? 2.3 >= parseFloat(RegExp.$1) ? "width=" + w + ", target-densitydpi=device-dpi" : "width=" + w + ", minimum-scale = " + scale + ", maximum-scale = " + scale + ", target-densitydpi=device-dpi" : "width=" + w + ", user-scalable=no, target-densitydpi=device-dpi";
        document.getElementById('eqMobileViewport').setAttribute("content", a);
    }

    function tr_appResize() {
        tr_setViewport(640);
        setTimeout(function () {
            tr_setViewport(638);
            setTimeout(function () {
                tr_setViewport(640);
            }, 100);
        }, 100);
    }


    tr_setViewport(640);
    //        window.addEventListener('resize', resize, false);
    window.addEventListener('orientationchange', tr_appResize, false);
    var ready = function (callback) {
        var readyRE = /complete|loaded|interactive/;
        if (readyRE.test(document.readyState)) callback();
        else document.addEventListener('DOMContentLoaded', function () {
            callback()
        }, false)
    };

    ready(function () {
        var u = navigator.userAgent;
        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        console.log($("input,select,textarea"), 2);
        if (isIOS) {
            var innerHeight = window.innerHeight;
            $("input,select,textarea").on("blur", function () {
                resetView(this)
            });

            function resetView(target) {
                // tr_setViewport(639);
                setTimeout(function () {
                    // tr_setViewport(640);
                    // target.scrollIntoView(false);
                    // window.scrollTo(0, 0);
                    // window.innerHeight = window.outerHeight = innerHeight;
                    document.activeElement.scrollIntoViewIfNeeded(true)
                }, 100);
            }
        }
    })


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值