Mootools-based rounded border extension code _mootools

Source: Internet
Author: User
Tags mootools
jquery below has an extension is the use of pure JS generated rounded corners, but and div+css spelled out is the same truth, rounded corners look relatively rough.

With the background picture lot better much, the problem is not stretching, the simplest way is to use four corner small picture plus border spelled out. But so much more than n pictures, a bunch of messy code, quite uncomfortable.

There is a very skillful way, with a large picture +css to do, the principle is as follows.

Use a large background image to do rounded corners, with CSS to take four corners and edges and then spell a Div. This will not only solve the fillet, but can also generate other special borders (such as shading).
But each use to add CSS is also very uncomfortable, so with MooTools wrote an extension of the element class.
Copy Code code as follows:

SetBorder
Element.implement ({
Setborder:function (pic, Len) {
<summary>
Sets the container border (picture).
Measured Div
</summary>
<param name= "pic" > Picture address </param>
<param name= "len" > Border width </param>
<returns type= "Element"/>
var content = This.clone ();
var width = this.getsize (). x + len * 2;
var height = this.getsize (). Y + len * 2;
This.empty (). Setstyles ({' width ': width, ' height ': height});
var lt = new Element (' div ', {
' Styles ': {
' Width ': len,
' Height ': len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat left top '
}
});
var rt = new Element (' div ', {
' Styles ': {
' Width ': width-len,
' Height ': len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') No-repeat right top '
}
});
var lb = new Element (' div ', {
' Styles ': {
' Width ': len,
' Height ': Height-len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat left Bottom '
}
});
var RB = new Element (' div ', {
' Styles ': {
' Width ': width-len,
' Height ': Height-len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat right Bottom '
}
});
Content.inject (RB, ' top ');
Lt.inject (this, ' top ');
Rt.injectbottom (this);
Lb.injectbottom (this);
Rb.injectbottom (this);
return this;
}
});



This will call the SetBorder method directly on the page to send a background picture, the border width in the line.

HTML code
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>untitled page</title>
<script type= "Text/javascript" src= "Mootools.js" ></script>
<script type= "Text/javascript" >
Element.implement ({
Setborder:function (pic, Len) {
<summary>
Sets the container border (picture).
Measured Div
</summary>
<param name= "pic" > Picture address </param>
<param name= "len" > Border width </param>
<returns type= "Element"/>
var content = This.clone ();
var width = this.getsize (). x + len * 2;
var height = this.getsize (). Y + len * 2;
This.empty (). Setstyles ({' width ': width, ' height ': height});
var lt = new Element (' div ', {
' Styles ': {
' Width ': len,
' Height ': len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat left top '
}
});
var rt = new Element (' div ', {
' Styles ': {
' Width ': width-len,
' Height ': len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') No-repeat right top '
}
});
var lb = new Element (' div ', {
' Styles ': {
' Width ': len,
' Height ': Height-len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat left Bottom '
}
});
var RB = new Element (' div ', {
' Styles ': {
' Width ': width-len,
' Height ': Height-len,
' Float ': ' Left ',
' Background ': ' url (' + pic + ') no-repeat right Bottom '
}
});
Content.inject (RB, ' top ');
Lt.inject (this, ' top ');
Rt.injectbottom (this);
Lb.injectbottom (this);
Rb.injectbottom (this);
return this;
}
});
Window.addevent (' Domready ', function () {
$ (' demo '). GetElements (' div '). each (function (d) {
D.setborder (' Border.png ', 8);
});
});
</script>
<body>
<div id= "Demo" >
<div style= "width:150px; height:100px; " >
<div style= "width:100%; height:100%; background-color:red; " ></div>
</div>
<div style= "width:80px; height:130px; " >
<div style= "width:100%; height:100%; Background-color:green; " ></div>
</div>
</div>
</body>


Show effects
MooTools Border Demo http://demo.jb51.net/js/mootools_yj/demo.htm
Package download
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title>untitled page</title> <sc Ript type= "Text/javascript" src= "http://img.jb51.net/jslib/mootools.js" ></script> <script type= "text/" JavaScript "> Element.implement ({setborder:function (pic, len) {///<summary>///set container border (picture). Measured div///</summary>///<param name= "pic" > Picture address </param>///<param name= "len" > Border width </para m>///<returns type= "Element"/> var content = This.clone (); var width = this.getsize (). x + len * 2; var height = this.getsize (). Y + len * 2; This.empty (). Setstyles ({' width ': width, ' height ': height}); var lt = new Element (' div ', {' styles ': {' width ': len, ' height ': len, ' float ': ' Left ', ' background ': ' URL ' + pic + ') No-repeat left Top '}}); var rt = new Element (' div ', {' StylEs ': {' width ': width-len, ' height ': len, ' float ': ' Left ', ' background ': ' URLs (' + pic + ') No-repeat right Top '} }); var lb = new Element (' div ', {' styles ': {' width ': len, ' height ': height-len, ' float ': ' Left ', ' background ': ' URL ' + pic + ') no-repeat left Bottom '}}); var RB = new Element (' div ', {' styles ': {' width ': width-len, ' height ': height-len, ' float ': ' Left ', ' background ') : ' url (' + pic + ') No-repeat right Bottom '}}); Content.inject (RB, ' top '); Lt.inject (this, ' top '); Rt.injectbottom (this); Lb.injectbottom (this); Rb.injectbottom (this); return this; } }); Window.addevent (' Domready ', function () {$ (' demo '). GetElements (' div '). each (function (d) {D.setborder ('/upload/ 2010-2/20100207111018894.png ', 8); }); }); </script> </pead> <body> <div id= "Demo" > <div > <div ></div> </div> <div > <div ></div> </div> </div> need to refresh to load external JS frame </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Previously used jquery also wrote one, incredibly can not find, but the principle is the same.

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.