Javascript function _ javascript skills that can achieve element rounded corners with simplified code

Source: Internet
Author: User
The JavaScript function that can implement element rounded corners with simplified code saw an implementation method for element rounded corners on blueidea last time, but that is too complicated. So I wrote a function to automatically round the elements.
Demo address: http://longbill.cn/down/sample/roundcorner.htm
Do not use the element with a padding value. It is best to set a layer on the outside. For details, see the demo address.
Code:
Function RoundCorner (obj, style)
{
/********
Page element rounded corner Function !!
By Longbill
Home: www.longbill.cn
********/
Var r = [];
Var styles = [
{Top: ["0 5px", "0 3px", "0 2px", "0 1px", "0 1px"], bottom: ["0 1px ", "0 1px", "0 2px", "0 3px", "0 5px"]},
{Top: ["0 5px", "0 3px", "0 2px", "0 1px", "0 1px"], bottom: ["0px ", "0px", "0px", "0px", "0px"]},
{Top: ["0 0 0 5px", "0 0 0 3px", "0 0 0 2px", "0 0 0 1px", "0 0 0 1px"], bottom: ["0 1 0 0px", "0 1 0 0px", "0 2 0 0px", "0 3 0 0px", "0 5 0 0px"]},
{Top: ["0 5 0 0px", "0 3 0 0px", "0 2 0 0px", "0 1 0 0px", "0 1 0 0px"], bottom: ["0 0 0 1px", "0 0 0 1px", "0 0 0 2px", "0 0 0 3px", "0 0 0 5px"]}
]; // Author: longbill.cn
If (! Style | style> styles. length) style = 1;
Style --;
Var btop = styles [style]. top, bbottom = styles [style]. bottom;
Obj = document. getElementById (obj );
If (! Obj) return;
Var HTML = obj. innerHTML;
Obj. innerHTML = "";
For (var istop = 1; istop> = 0; istop --)
{
Var topborder = document. createElement ("B ");
Topborder. style. display = "block ";
Topborder. style. height = "2px ";
Topborder. style. backgroundColor = (obj. parentNode. style. backgroundColor )? Obj. parentNode. style. backgroundColor: "# FFFFFF ";
For (var I = 0; I {
Var B = document. createElement ("B ");
If (obj. style. backgroundColor)
B. style. backgroundColor = obj. style. backgroundColor;
Else if (obj. className)
B. className = obj. className;
B. style. display = "block ";
B. style. margin = (istop )? Btop [I]: bbottom [I];
B. style. height = "1px ";
B. style. overflow = "hidden ";
B. style. width = "auto ";
Topborder. appendChild (B );
}
Obj. appendChild (topborder );
If (istop) obj. innerHTML + = 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.