美文网首页
移动端设置 font-size

移动端设置 font-size

作者: cench | 来源:发表于2017-04-23 13:54 被阅读168次
网易方案

设计稿尺寸为750,设置font-size为:50px

  <script type="text/javascript">
        var Dpr = 1,
            uAgent = window.navigator.userAgent;
        var isIOS = uAgent.match(/iphone/i);
        var isYIXIN = uAgent.match(/yixin/i);
        var is2345 = uAgent.match(/Mb2345/i);
        var ishaosou = uAgent.match(/mso_app/i);
        var isSogou = uAgent.match(/sogoumobilebrowser/ig);
        var isLiebao = uAgent.match(/liebaofast/i);
        var isGnbr = uAgent.match(/GNBR/i);
        function resizeRoot() {
            var wWidth = (screen.width > 0) ? (window.innerWidth >= screen.width || window.innerWidth == 0) ? screen.width :
                            window.innerWidth : window.innerWidth,
                    wDpr, wFsize;
            var wHeight = (screen.height > 0) ? (window.innerHeight >= screen.height || window.innerHeight == 0) ?
                    screen.height : window.innerHeight : window.innerHeight;
            if (window.devicePixelRatio) {
                wDpr = window.devicePixelRatio;
                console.log(wDpr)
            } else {
                wDpr = isIOS ? wWidth > 818 ? 3 : wWidth > 480 ? 2 : 1 : 1;
            }
            if (isIOS) {
                wWidth = screen.width;
                wHeight = screen.height;
            }
            // if(window.orientation==90||window.orientation==-90){
            //     wWidth = wHeight;
            // }else if((window.orientation==180||window.orientation==0)){
            // }
            if (wWidth > wHeight) {
                wWidth = wHeight;
            }
            wFsize = wWidth > 1080 ? 144 : wWidth / 7.5;
            debugger
            wFsize = wFsize > 32 ? wFsize : 32;
            console.log('fsize:'+wFsize)
            window.screenWidth_ = wWidth;
            if (isYIXIN || is2345 || ishaosou || isSogou || isLiebao || isGnbr) { //YIXIN 和 2345 这里有个刚调用系统浏览器时候的bug,需要一点延迟来获取
                setTimeout(function () {
                    wWidth = (screen.width > 0) ? (window.innerWidth >= screen.width || window.innerWidth == 0) ?
                            screen.width : window.innerWidth : window.innerWidth;
                    wHeight = (screen.height > 0) ? (window.innerHeight >= screen.height || window.innerHeight ==
                    0) ? screen.height : window.innerHeight : window.innerHeight;
                    wFsize = wWidth > 1080 ? 144 : wWidth / 7.5;
                    wFsize = wFsize > 32 ? wFsize : 32;
                    // document.getElementsByTagName('html')[0].dataset.dpr = wDpr;
                    document.getElementsByTagName('html')[0].style.fontSize = wFsize + 'px';
                    document.getElementById("fixed").style.display = "none";
                }, 500);
            } else {
                // document.getElementsByTagName('html')[0].dataset.dpr = wDpr;
                document.getElementsByTagName('html')[0].style.fontSize = wFsize + 'px';
            }
             // alert("fz="+wFsize+";dpr="+window.devicePixelRatio+";UA="+uAgent+";width="+wWidth+";sw="+screen.width+";wiw="+window.innerWidth+";wsw="+window.screen.width+window.screen.availWidth);
        }
        resizeRoot();
        if (location.protocol === "https:") {
            location.href = location.href.replace("https:", "http:")
        }
        window.onresize = function () {
            console.log('resize')
            resizeRoot();
        }
    </script>

相关文章

  • 移动端设置 font-size

    网易方案 设计稿尺寸为750,设置font-size为:50px

  • 常用响应式

    rem 通过设置不同屏幕尺寸html的font-size实现响应式PC端 移动端 vw/vh rem弊端:具有阶梯...

  • 移动端使用sweetAlert填一个小坑

    移动端使用sweetAlert时,不要在css里设置html元素的font-size值,否则会影响sweetAle...

  • 说说rem

    rem单位是在移动端布局中最常使用的单位通常做法是设置html{font-size:62.5%},然后使用媒体查询...

  • 移动端html font-size动态计算设置

    设计稿以750px为宽度,其中有个元素是100px;如何设置font-size,使同一段代码在不同的设备上保持一致...

  • 移动端开发(Html+Css)

    placeholder自定义 移动端适配CSS方案 移动端适配方案一 font-size可能需要额外的媒介查询,并...

  • 移动端自动变更html,设置rem

    代码可以直接写在html中,也可以也成 .js 文件,方便调用。 根据这一句 docEl.style.fontSi...

  • 移动端font-size适配

    屏幕宽度 机制是:对于不同宽度的屏幕,我们用js取到屏幕的宽度,然后根据这个宽度同比缩放font-size,由于我...

  • 移动端设置

    正确设置默认设置后,大多数用户很少访问“设置”页面。但是,当紧急情况发生时,用户应该可以轻松找到正确的设置并应用更...

  • 移动端

    app Web App Hybird App 移动端页面 设计图 测试 移动端的设置 移动端的布局 弹性 fl...

网友评论

      本文标题:移动端设置 font-size

      本文链接:https://www.haomeiwen.com/subject/heqyzttx.html