zoukankan      html  css  js  c++  java
  • rem 自适应布局 js 代码

    在前面head里面加上这一句禁止缩放:
     
     <meta name="viewport"
            content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
     
    以下是js代码 该代码1rem=100px :
     
    !(function(win, doc) {
        function setFontSize() {
            var winWidth = window.innerWidth;
            doc.documentElement.style.fontSize = (winWidth / 1080) * 100 + 'px';
        }
        var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';
        var timer = null;
        win.addEventListener(evt, function() {
            clearTimeout(timer);
            timer = setTimeout(setFontSize, 300);
        }, false);
        win.addEventListener("pageshow", function(e) {
            if (e.persisted) {
                clearTimeout(timer);
                timer = setTimeout(setFontSize, 300);
            }
        }, false);
        //初始化 
        setFontSize();
    }(window, document));
  • 相关阅读:
    数据库 mysql 语句
    document对象
    javascript
    css样式表及属性
    css格式布局
    html 标签
    html 标签
    第四章
    第三章
    第二章
  • 原文地址:https://www.cnblogs.com/an2333/p/11608487.html
Copyright © 2011-2022 走看看