zoukankan      html  css  js  c++  java
  • 动态获取移动端视宽,从而结合rem达到适配

    // 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";
        }
    }();
  • 相关阅读:
    SpringBoot与(Security)安全
    SpringBoot任务
    SSM框架整合思路
    数据库连接池 Druid和C3p0
    YAML语法:
    Mbatis使用
    为什么要使用Mybatis-现有持久化技术的对比
    SpringMVC拦截器
    ARC109D
    一类求斯坦纳树大小的问题
  • 原文地址:https://www.cnblogs.com/520BigBear/p/9610083.html
Copyright © 2011-2022 走看看