Dynamically change the introduced CSS file

Source: Internet
Author: User
Window. onload = function (){
Setlinetextfrontwidth ();
}
Function setlinetextfrontwidth (){
VaR curtotalwidth = (document.doc umentelement. clientwidth = 0 )? Document. Body. clientwidth: document.doc umentelement. clientwidth;
If (curtotalwidth <= 100) {return ;}
Curtotalwidth = fig-100;
VaR classes = Document. stylesheets [0]. Rules | document.stylesheets%0%.css rules;
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;
}
}
}

 

The Multi-Resolution CSS mode and window change are also optimized.

Window. onload = function (){
Setlinetextfrontwidth ();
}
Window. onresize = function (){
Setlinetextfrontwidth ();
}
Function setlinetextfrontwidth (){
VaR curtotalwidth = (document.doc umentelement. clientwidth = 0 )? Document. Body. clientwidth: document.doc umentelement. clientwidth;
If (curtotalwidth <= 100) {return ;}
VaR vfontwidth = curtotalwidth-100;
VaR classes = Document. stylesheets [0]. Rules | document.stylesheets%0%.css rules;
If (curtotalwidth> = 1024 ){
Setlinetextfrontwidthbyminwidth (class, 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-width: '+ vminwidth + 'px )'){
VaR classes = vclass [X]. Rules | vclass?x=.css rules;
Setlinetextfrontwidthstyle (classes, vwidthpx );
Break;
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.