CSS background gradient

Source: Internet
Author: User

<! Doctype HTML public '-// W3C // dtd html 4.01 // en' 'HTTP: // www.w3.org/tr/html4/strict.dtd'>
<HTML>
<Head>
<Meta http-equiv = Content-Type content = "text/html; charset = GBK">
<Title> gradient background </title>

<SCRIPT>

VaR setgradient = (function (){

// Private variables;
VaR p_dcanvas = Document. createelement ('canvas ');
VaR p_usecanvas = !! (Typeof (p_dcanvas.getcontext) = 'function ');
VaR p_dctx = p_usecanvas? P_dcanvas.getcontext ('2d '): NULL;
VaR p_isie =/* @ cc_on! @ */False;

// Test if todataurl () is supported by canvas since Safari may not support it

Try {p_dctx.canvas.todataurl ()} catch (ERR ){
P_usecanvas = false;
};

If (p_usecanvas ){

Return function (Del, scolor1, scolor2, brepeaty ){

If (typeof (DEL) = 'string') del = Document. getelementbyid (DEL );
If (! Del) return false;
VaR nw = del. offsetwidth;
VaR nH = del. offsetheight;
P_dcanvas.width = NW;
P_dcanvas.height = nH;

VaR dgradient;
VaR srepeat;
// Create gradients
If (brepeaty ){
Dgradient = p_dctx.createlineargradient (0, 0, NW, 0 );
Srepeat = 'Repeat-y ';
} Else {
Dgradient = p_dctx.createlineargradient (0, 0, NH );
Srepeat = 'Repeat-x ';
}

Dgradient. addcolorstop (0, scolor1 );
Dgradient. addcolorstop (1, scolor2 );

P_dctx.fillstyle = dgradient;
P_dctx.fillrect (0, 0, NW, NH );
VaR sdataurl = p_dctx.canvas.todataurl ('image/PNG ');

With (DEL. Style ){
Backgroundrepeat = srepeat;
Backgroundimage = 'url ('+ sdataurl + ')';
Backgroundcolor = scolor2;
};
}
} Else if (p_isie ){

P_dcanvas = p_usecanvas = p_dctx = NULL;
Return function (Del, scolor1, scolor2, brepeaty ){
If (typeof (DEL) = 'string') del = Document. getelementbyid (DEL );
If (! Del) return false;
Del. style. Zoom = 1;
VaR Sf = del. currentstyle. filter;
Del. style. Filter + = ''+ ['progid: DXImageTransform. Microsoft. gradient (gradienttype = ', + (!! Brepeaty), ', enabled = true, startcolorstr =', scolor1, ', endcolorstr =', scolor2, ')']. Join ('');

};

} Else {

P_dcanvas = p_usecanvas = p_dctx = NULL;
Return function (Del, scolor1, scolor2 ){

If (typeof (DEL) = 'string') del = Document. getelementbyid (DEL );
If (! Del) return false;
With (DEL. Style ){
Backgroundcolor = scolor2;
};
// Alert ('your browser does not support gradient effet ');
}
}
})();

</SCRIPT>

<Style>
Body {Font: 0.75em/1.4 Arial; text-align: Left; margin: 20px ;}
HR {clear: Both; visibility: hidden ;}
XMP {Font: 12px/12px "Courier New"; Background: # FFF; color: #666; Border: solid 1px # CCC ;}
Div. example {border: solid 1px #555; margin: 0 20px 20px 0; float: Left; display: inline; margin: 1em; Background: # FFF; width: 300px; padding: 40px; color: #222; Font: XX-small/1.2 "tahoma"; text-align: justify ;}
</Style>

<Body>

<H1> gradient background-beta1 <H4> IE6, IE7, and ff2 passed the test. </H4>

<Div id = "example1" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, presponeget, ipsum. etiam Magna urna, ultrices ut, EU </div>

<Div id = "example2" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, pretiu </div>

<Div id = "example3" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, presponeget, ipsum. etiam Magna urna </div>

<Div id = "example4" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, presponeget, ipsum. etiam Magna urna, ultrices ut, euismod in, lobortis Tempus, ipsum. fusce risus Tellus, interdum sit Amet, </div>

<Div id = "example5" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, presponeget, ipsum. etiam Magna urna, ultrices ut, euismod in, lobortis Tempus, ipsum. fusce risus Tellus, interd </div>

<Div id = "example6" class = "example">
Lorem ipsum dolor sit Amet, consectetuer adipiscing elit. aliquam blandit nunc lobortis diam Bibendum semper. nunc aliquam mi. maecenas porttitor, lorem sed Mattis ultrices, lorem risus consequat Mi, Vitae ullamcorper Leo ipsum in Tellus. pellentesque arcu est, sollicitudin SED, ultricies Quis, vestibulum A, neque. DUIs massa elit, gravida Vel, lacinia EU, presponeget, ipsum. etiam Magna urna, ultrices ut, euismod in, lobortis Tempus, ipsum. fusce risus Tellus, interd </div>

 

<SCRIPT>
Setgradient ('example1', '# 4ddbbe', '# d449cc', 1 );
Setgradient ('example2', '# 46ddbd', '# d8b617', 0 );
Setgradient ('example3', '# c81fc1', '# bf445f', 1 );
Setgradient ('example4', '#2285e5', '# d769eb', 0 );
Setgradient ('example5', '#8b4286', '# eac87d', 1 );
Setgradient ('example6', 'black', 'white', 0 );
</SCRIPT>

</Body>
</Html>

Related Article

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.