|
Jquery Rounded Corners Plugin Example - cross browser CSS replacement |
This article deals with a JQuery plugin that can emulate a totally cross browser CSS3 rounded corners solution.
There is an example of the finished code here: JQuery Rounded Corners example
First thing is to call the JQuery library, and the download the corner.js file. You can get it here: http://www.malsup.com/jquery/corner/. That site is also where I got most of the examples and source for my example above, its shows the huge variety of display options the plugin has.
The really good thing about this plugin is that it tries to apply the standard CSS3 rounded corner code first, so any browser that natively supports CSS3 will use that.
Create any div's you want to be rounded. Below I'm creating three div's each with different class names to be used when applying border effects.
2 </div>
3
4 <div class="inner rounded-top">
5 </div>
6
7 <div class="inner rounded-bottom">
8 </div>
Next create your JQuery function that applies the plugin to your selected classes. Below I am using the JQuery wrap() function to auto write a wrapper div around any '.rounded' div. This creates the thin line edge.
2 $(document).ready(function(){
3 $('.rounded').wrap('<div class="outer"></div>');
4 $('.rounded').corner("round 8px").parent().css('padding', '2px').corner("round 10px");
5
6 $('.rounded-top').corner("top");
7
8 $('.rounded-bottom').corner("bottom");
9 });
10</script>
The last two lines are more standard, they simply create top and bottom rounded corners respectively.
In my example above I wanted a solid differently coloured border around the div, so we are wrapping our content div in another div, and altering its border to being rounded as well.
There is an example of the finished code here: JQuery Rounded Corners example
There are no comments for this entry.
[Add Comment] [Subscribe to Comments]