zoukankan      html  css  js  c++  java
  • 动态改变引入的CSS文件

            window.onload = function(){
                setLineTextFrontWidth();
            }
            function setLineTextFrontWidth(){
                var curTotalWidth = (document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth;
                if(curTotalWidth<=100){ return; }
                curTotalWidth = curTotalWidth - 100;
                var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
                var hasChangeL1 = false;
                var hasChangeL2 = false;
                for(var x=0;x<classes.length;x++) {
                    if( classes[x].selectorText=='.LineText1Front' ) {
                        hasChangeL1 = true;
                           classes[x].style.width = '' + curTotalWidth + 'px';
                    }else if(classes[x].selectorText=='.LineText2Front'){
                        hasChangeL2 = true;
                           classes[x].style.width = '' + curTotalWidth + 'px';
                    }
                    if( hasChangeL1 && hasChangeL2 ){
                        break;
                    }
                }
            }

    再优化一次多分辨率CSS模式及窗口改变也进行处理 


        window.onload = function(){
                setLineTextFrontWidth();
            }
            window.onresize = function(){
                setLineTextFrontWidth();
            }
    function setLineTextFrontWidth(){
        var curTotalWidth = (document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth;
        if(curTotalWidth<=100){ return; }
        var vFontWidth = curTotalWidth - 100;
        var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
        if(curTotalWidth>=1024){
            setLineTextFrontWidthByMinWidth(classes,vFontWidth,1024);
        }else{
            setLineTextFrontWidthStyle(classes,vFontWidth);
        }
    }
    function setLineTextFrontWidthStyle(vClass,vWidthPx){
        for(var x=0;x<vClass.length;x++) {
            if( vClass[x].selectorText=='.LineText1Front' || vClass[x].selectorText=='.LineText2Front' ) {
                    vClass[x].style.width = '' + vWidthPx + 'px';
            }
        }
    }
    function setLineTextFrontWidthByMinWidth(vClass,vWidthPx,vMinWidth){
        for(var x=0;x<vClass.length;x++) {
            if (vClass[x].type == '4' && vClass[x].media.mediaText == 'only screen and (min- '+vMinWidth+'px)') {
                 var classes = vClass[x].rules || vClass[x].cssRules;
                 setLineTextFrontWidthStyle(classes,vWidthPx);
                 break;
             }
        }

    } 

  • 相关阅读:
    tensorflow2.0第1章 Tensorflow简介与环境搭建
    SIGAI机器学习第二十四集 聚类算法1
    SIGAI机器学习第二十三集 高斯混合模型与EM算法
    51nod1429 巧克力
    CTSC2018 Day2T1 Juice混合果汁
    CF1B Spreadsheets
    CF2B The least round way
    【模板】点分治
    【模板】AC自动机
    【模板】网络流-最大流 Dinic
  • 原文地址:https://www.cnblogs.com/abinxm/p/2456971.html
Copyright © 2011-2022 走看看