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";
        }
    }();
  • 相关阅读:
    库函数文件操作
    系统文件操作函数
    time函数
    字符(串)输入输出函数
    select&epoll
    epoll
    select
    Apache 配置虚拟主机三种方式
    Apache VirtualHost配置
    Scrapy中用xpath/css爬取豆瓣电影Top250:解决403HTTP status code is not handled or not allowed
  • 原文地址:https://www.cnblogs.com/520BigBear/p/9610083.html
Copyright © 2011-2022 走看看