Recently I've been searching for a method of creating nice looking rounded corners with Javascript & JQuery.
First I found the "JQuery Corner" plugin for rounded corners, but was disappointed that it did not include smooth, anti-aliased corners.
I then did some more google-trawling and found this post, which contained a modified version of Curvy Corners for use with JQuery. Now this script was much much better.
However…the filesize was a massive 40kb, way too big for production use, and to make things worse the code was not compatible with packer so I could not reduce the filesize.
Well, I got busy, and fixed the errors. It is now fully packer friendly meaning easy rounded corners in JQuery at only 9kb 8kb. Excellent. Read more for the download link.
Demo and download
You can download the fixed source code, and the compressed version below!
Downloaded a total of 11728 times
The packed version is only 8kb, the uncompressed version is 28kb (thats half the size of the original script!).
Quick example
To make a curvy cornered box simply use:
1 | $('.round_this').corner(); |
Thats all there is too it. A great script!
For more information on Curvy Corners, check out its official site.!
*Edit: Found a small error in IE7 with the backgroundPosition property, fixed now. New file uploaded.
*Edit 2 - 25th Sep 07: More optimizations, smaller file!
*Edit 3 - 29th Sep 07: More optimizations, smaller file, and demo page up!
*Edit 4 - 6th March 08: New version up with better background image support.
Share This











109 - Kyle says:
This is a nice plugin, and the size isn\’t too bad when compared to others and considering the extra features this one has (and more versatile from what I can tell).
But, with AA on it\’s slow as hell which can be a problem if an element is changing colours. Have you thought about implementing a method to just change the colours of the background and border rather than rebuild the whole thing? You could then cache each radius + border size and reuse each chunk of html as well, which could speed up things if a page has say 2+ elements with the same border and radius size.
Would it actually be faster to go through a bunch of elements and change the css than to rebuild the whole thing though? I assume so and I\’ll probably give it a go myself when I have time to come back to such details.
Also most of the this\’s in the code are redundant. Since they\’re in so many places they might even add up to a whole 0.1kb. Similarly a lot of the vars could be dropped by declaring the variables on the same line. The current script also keeps switching between jQuery style coding and normal javascript and the whole thing isn\’t conflict safe.
I\’m sure the whole thing could be rewritten even smaller by understanding the concept and starting from scratch rather than editing another script.
Comment made on May 1, 2008 at 11:53 am
110 - Graham Gilbert says:
I love this pugin, and use it all the time, but I’ve run into a bug. Other developers that I work with insist on using things such as mootools, so I need to use something like var $j = jQuery.noConflict(); but this plugin doesn’t work with that method. Any idea why?
Comment made on May 5, 2008 at 8:41 pm
111 - Mike Jolley says:
@Graham - Because I have not used jquery() functions, ive used shorthand $(). You can search and replace them perhaps to make it work.
Comment made on May 5, 2008 at 9:09 pm
112 - klemen says:
Hi,
Great work!
When I use your plugin it adds some additional padding.
This plugin doesen’t do that: http://www.methvin.com/jquery/jq-corner.html
If you could fix this it would be really great
Comment made on May 5, 2008 at 11:23 pm
113 - Fret says:
Sorry to be so stupid but in what way is this a plugin? There seems to be no explanation of how this is used in connection with Wordpress. Could anyone please point me in the right direction?
Comment made on May 6, 2008 at 7:16 pm
114 - Mike Jolley says:
@Fret - No where does it say its a wordpress plugin; its a jquery plugin :s
Comment made on May 6, 2008 at 7:21 pm
115 - Serhat Yolaçan » 10 Adet kullanışlı AJAX uygulaması says:
[...] Rounded Corners With AJAX Yuvarlaklaştırılmış köşeler. [...]
Pingback made on May 11, 2008 at 4:57 pm
116 - Jeronimo Martinez Sanchez says:
great plugin, i made a hack to use transparent background and display only the rounded borders.
make some changes on the function BlendColour() adding a validation, here is the code:
function BlendColour(Col1, Col2, Col1Fraction) {
// JM: transparent Col1 result in “#undefined”.
if(Col1 == “transparent”) {
return “transparent”;
} else {
var red1 = parseInt(Col1.substr(1,2),16);
var green1 = parseInt(Col1.substr(3,2),16);
var blue1 = parseInt(Col1.substr(5,2),16);
var red2 = parseInt(Col2.substr(1,2),16);
var green2 = parseInt(Col2.substr(3,2),16);
var blue2 = parseInt(Col2.substr(5,2),16);
if(Col1Fraction > 1 || Col1Fraction 255) endRed = 255;
if(endRed 255) endGreen = 255;
if(endGreen 255) endBlue = 255;
if(endBlue < 0) endBlue = 0;
return “#” + IntToHex(endRed)+ IntToHex(endGreen)+ IntToHex(endBlue);
}
};
and the other change is in the format_colour(colour) function changed the returnColour to transparent.
Comment made on May 12, 2008 at 9:48 pm
117 - meekish says:
[PATCH]
63: $(this.box).css(”padding”,”0px !important”);
Does not change the padding in FF3. Since inline styles take highest precedence, the ‘!important’ should not be needed. The fix is to simply remove it:
63: $(this.box).css(”padding”,”0px”);
Comment made on May 13, 2008 at 5:16 am
118 - sastgroup.com » Blog Archive » 240 plugins jquery says:
[...] Corner. jQuery Curvy Corner. Nifty jQuery Corner. Transparent Corners. jQuery Corner Gallery. Gradient [...]
Pingback made on May 13, 2008 at 7:40 pm