首页 > 移动平台 > 详细

动态获取移动端视宽,从而结合rem达到适配

时间:2018-09-08 19:13:28      阅读:135      评论:0      收藏:0      [点我收藏+]
// jq
        !function(){
            var windowWidth= $(window).width();
            if(windowWidth > 750) {
                windowWidth = 750;
            }
            var fontSize = windowWidth / 750 * 50;//50是html根元素font-size值

            $("html").attr("style", "font-size:" + fontSize + "px");
            $(window).resize(function() {
                windowWidth = $(window).width();
                if(windowWidth > 750) {
                    windowWidth = 750;
                }
                fontSize = windowWidth / 750 * 50;
                $("html").attr("style", "font-size:" + fontSize + "px");
            });
        }();


//js
!function(){
    var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
    if(windowWidth > 750) {
        windowWidth = 750;
    }
    var fontSize = windowWidth / 750 * 50;   //50是html根元素font-size值

    document.getElementsByTagName(‘html‘)[0].style.fontSize = fontSize + "px";
    window.onresize = function(){
        var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
        if(windowWidth > 750) {
            windowWidth = 750;
        }
        fontSize = windowWidth / 750 * 50;
        document.getElementsByTagName(‘html‘)[0].style.fontSize = fontSize + "px";
    }
}();

 

动态获取移动端视宽,从而结合rem达到适配

原文:https://www.cnblogs.com/520BigBear/p/9610083.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!