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;
             }
        }

    } 

  • 相关阅读:
    Dojo中的模块插件
    CommonJS、AMD和RequireJS、NodeJS之间的关系
    require函数
    AMD(异步模块定义规范)
    理解apply()和call()
    JavaScript中的Function类型
    4.1 基本类型和引用类型的值【JavaScript高级程序设计第三版】
    10.1.2 Document类型【JavaScript高级程序设计第三版】
    10.2 DOM 操作技术【JavaScript高级程序设计第三版】
    3.4.2 Undefined类型【JavaScript高级程序设计第三版】
  • 原文地址:https://www.cnblogs.com/abinxm/p/2456971.html
Copyright © 2011-2022 走看看