Anti-aliased Rounded corners with JQuery

Rounded CornersRecently 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 15kb 20kb 16kb 10kb. Excellent. Read more for the download link.

Demo and download

You can also grab the plugin from Google Code.

Download JQuery Curvy Corners Version 1.9

The packed version is only 10kb, the uncompressed version is 23kb (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.

*Edit 5 – 19th May 08: No extra padding, safari fixed, larger filesize to reduce overhead and increase speed.

*Edit 6 – 9th Aug 08: General fixes from feedback

*Edit 7 – 7th Oct 08: Major overhaul to improve compatibility with other plugins

*Edit 8 – 2nd June 09: Now compatible with jquery 1.3.2 – All future updates will be on Google Code (http://code.google.com/p/jquerycurvycorners/) – Hence im closing comments here. Post your contributions either on google code or in the forum.

Found this post useful? Why not buy me a coffee!

Related Entries

307 Responses to “Anti-aliased Rounded corners with JQuery”

RSS feed for comments on this post.

  1. Ryan says:

    $($$ +" *").css("zoom","normal");

    I found commenting only this line out made it work in IE6/IE7 and Firefox. I haven’t tested anything else yet, but I’m feeling lucky.

    Thanks Niels.

    Comment made on January 30, 2009 at 10:38 pm

  2. jeroen says:

    Thanks Niels & Ryan for trying to solve the problem.

    However, with the latest solution I´m seeing some very strange things in IE6: After loading of the page, counting down to 0 Items Remaining (loading photos etc.), it goes up again to hundreds of Items Remaining and the background in the corners of the rounded boxes is filled in pixel by pixel, taking about a minute for a few rounded boxes with background images.

    I should say that I only have MultipleIEs to test IE6, but as far as I know, that´s a valid IE6 version.

    Does anybody else notice this behaviour?

    By the way, the end result looks good!

    Comment made on January 31, 2009 at 12:08 am

  3. Mike Jolley says:

    Thanks for trying fixes; Ill may patch this version, however, I would much rather wait for the official CC script beforehand because its new version (2) is in beta and soon to be finished.

    Comment made on January 31, 2009 at 1:59 pm

  4. jeroen says:

    @Mike Jolley: Thanks for a great plugin, looking forward to version 2!

    Comment made on January 31, 2009 at 7:57 pm

  5. Ryan says:

    jeroen - I was having this issue too. I thought it was something else in the intense AJAX app I’m building though. We have a testing machine here with an actual version of IE6, and although I get the same issue as you in the standalone (MultipleIEs), the real version seems ok. Everything is very slow however, but we test on an old PIII 450mhz with 256mb of RAM, and everything is generally quite slow on that machine. Mike, thanks for the script. I may just not give IE6 rounded corners if it comes to that.

    Comment made on February 2, 2009 at 9:28 pm

  6. Aaron says:

    I am having the same issues in IE using jQuery 1.31 and get an error.

    I have commentted out the $($$ +” *”).css(“zoom”,”normal”); but was wondering if anyone had any luck or a new version is going to be released with a fix for the new jQuery code?

    Great script!!!!

    Cant wait to see an update fixing this problem! :)

    Comment made on February 4, 2009 at 5:37 pm

  7. jeroen says:

    Ryan – Thanks for the confirmation, I think I´ll just stick with jquery 1.2.6 for the time being: The site requires IE6 support and doesn´t use much jquery / javascript functionality apart from the rounded corners.

    Comment made on February 6, 2009 at 2:58 pm

  8. manuel says:

    guys, i download the example as it is, and it’s not working in IE6, please, ig some of you know what could it be, i will appreciate it

    regards.

    Comment made on February 7, 2009 at 9:25 am

  9. Mike says:

    IE7 support breaks with jquery 1.3.1. No huge deal to drop down to 1.2.6. for me though, just thought I’d let you know.

    Comment made on February 11, 2009 at 11:15 pm

  10. gremki says:

    Regarding IE6 error: just change
    $($$ +" *").css("zoom","normal");
    to
    $("*", $$).css("zoom","normal");
    and should work just fine on jQuery 1.3

    Comment made on February 16, 2009 at 11:15 am

  11. Tom says:

    Hi… I am having some trouble with jQuery 1.3 and this script in IE7… could you fix it?

    Comment made on February 17, 2009 at 11:32 pm

  12. Tom says:

    @Tom:
    The solution of gremki is the best, I think.

    Comment made on February 17, 2009 at 11:40 pm

  13. Zajda says:

    Nice. But it doesnt work in Google Chrome when DIV has transparent PNG background. It makes DIVs top and bottom color red… :(

    Comment made on February 23, 2009 at 11:31 pm

  14. topherez says:

    Same here… top and bottom of the cornered div is red in Safari. Auto-pad is also broken.

    The div style that is being rendered-out appears like this:

    overflow: hidden; height: 1px; width: 1px; position: absolute; font-size: 1px; background-color: rgb(255, 0, 0); opacity: 0.974937; top: 9px; left: 0px;

    Comment made on February 24, 2009 at 7:50 pm

  15. sven says:

    It does not work on IE7 and latest(1.3) jQuery

    Comment made on February 26, 2009 at 12:47 pm

  16. wingrunr says:

    I have fixed the Safari problem. There were a number of edits needed for the code to function properly. The problem lies in the fact that Safari does not return a transparent background as “transparent” but rather returns “rgba(0, 0, 0, 0)”. A filter for this needs to be added in format_color so the new if statement looks like this:

    if(colour != "" && colour != "transparent" && colour != "rgba(0, 0, 0, 0)")

    Likewise in rgb2Array an improper substring was being extracted for rgba attributes so the code needs to be changed to this:

    var rgbValues = null;

    if (rgbColour.substr(0, 4) == "rgba")
    rgbValues = rgbColour.substring(5, rgbColour.indexOf(")"));
    else
    rgbValues = rgbColour.substring(4, rgbColour.indexOf(")"));

    var rgbArray = rgbValues.split(", ");
    return rgbArray;

    That will render the corners correctly in Safari.

    Comment made on March 1, 2009 at 6:47 am

  17. wingrunr says:

    By the way, for anyone that would like a minified/source fixed version including gremki’s fix for IE7, you can get them at these two URLs for now:

    http://www.northpolesoftware.com/files/jquery.curvycorners.min.js
    http://www.northpolesoftware.com/files/jquery.curvycorners.source.js

    I’ll leave these up until Mike can grab them and mirror them again.

    Comment made on March 1, 2009 at 7:11 am

  18. Bruno says:

    It isn’t working for me on both IE’s, any idea why? Thanks!

    Comment made on March 2, 2009 at 7:48 pm

  19. Bruno says:

    So the problem is that this plugin doesn’t run on jquery latest version… can this be solved? last versions (1.3.2) is much faster. Maybe because the new CSS selector?

    Comment made on March 3, 2009 at 11:31 am

  20. Bruno says:

    But this works:
    ——————
    #
    311 – gremki says: Reply to this comment
    Gravatar

    Regarding IE6 error: just change
    $($$ +” *”).css(“zoom”,”normal”);
    to
    $(“*”, $$).css(“zoom”,”normal”);
    and should work just fine on jQuery 1.3

    Comment made on February 16, 2009 at 11:15 am

    Comment made on March 3, 2009 at 11:40 am

  21. David Resseguie says:

    Bruno/gremki,

    Thanks! Making the change suggested in #311 did, in fact, fix the problems I was having in IE 7 using the latest jQuery.

    Added the info to the bug tracking system here:
    http://plugins.jquery.com/node/5756

    Much appreciated!
    David

    Comment made on March 3, 2009 at 9:58 pm

  22. Niels says:

    Another bug with IE7 (maybe 6 also).

    At least one top or one bottom corner needs to be specified. If both top or both bottom corners are omitted (false in options), IE gives an error stating “invalid argument”.

    Bug doesn’t occur in FF3 or Safari 3.

    Comment made on March 11, 2009 at 3:56 pm

  23. Niels says:

    With regard to the bug in 330.

    The error only occurs when a border is set on the DIV segment.

    *does further investigation*

    Comment made on March 11, 2009 at 4:27 pm

  24. Niels says:

    @Niels:

    Ok, bug found and fixed.

    On line 306: $(contentContainer).css({position:”relative”, ‘float’:”left”,width:”100%”, “margin-top”:”-” + (topMaxRadius-borderWidth) + “px”, “margin-bottom”:”-” + (botMaxRadius-borderWidth) + “px”}).addClass = “autoPadDiv”;

    Change to:

    $(contentContainer).css({position:”relative”, ‘float’:”left”,width:”100%”, “margin-top”:”-” + Math.abs(topMaxRadius-borderWidth) + “px”, “margin-bottom”:”-” + Math.abs(botMaxRadius-borderWidth) + “px”}).addClass = “autoPadDiv”;

    Maybe not even a IE bug but a FF bug. I think the original line causes a double – (minus) sign when borderWidth > 0 and corner radius = 0 for both top or bottom corners.

    Comment made on March 11, 2009 at 4:53 pm

  25. Jakobud says:

    @Niels:
    That fix you posted in 332, not sure what that was supposed to fix (as I wasn’t getting that javascript error in IE) but when I apply it, it breaks the rounded corner functionality in Firefox.

    I have another issue though:

    In IE6/7, has anyone noticed the small pink background that shows through when you apply a border of any size to the rounded corner element?

    Take a look at the following screenshot. These are simply just DIV elements with a white background that I have black borders applied to them. That pink only shows up when borders are present. Doesn’t seem to matter what size/width the borders are.

    http://img3.imageshack.us/my.php?image=roundedcornerpink.jpg

    Any thoughts?

    Comment made on March 12, 2009 at 5:41 pm

The comments are closed.

About this site

Blue Anvil is the online web design journal & portfolio of , a web designer from Norfolk, England. Read More »
ThemeSlice
  • Featured work - More

    • Beefjack
    • Integrity
    • theotaku.com
  • Latest Tweet - More

    • @skjreilly no problem :)
  • Out of the blue - More

    • Switched: From Shared to VPS

      It’s been about two weeks now since I made the transition from a shared reseller hosting account to a VPS (Virtual Private Server) account – impressions so far, excellent performance but fiddly to configure.

      The reason I wanted to change from shared hosting was the fact the server was always being hacked (even though ALL my scripts were secure), there was frequent downtime, support blamed me for problems every time, and it was slow as hell.

      Those used to a shared hosting environment would probably not know where to start when faced with configuring a VPS. Luckily, a lot of it was pre-configured when I received my account – certainly some of the major security holes were patched. I was not satisfied with those however. As a victim of hacking in the past (previous host swears it was not there fault, something I don’t believe) I took extra care to secure it as a much I could – configuring brute force detection, the firewall, installing mod security (excellent rules for that here: http://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules) and going though multiple guides (like this one: http://www.webhostingtalk.com/showthread.php?t=468168) with a fine-tooth comb.

      The result? My pages are loading at least 6 times faster, I have had no down time (or at least have not noticed any), and I feel in control and happy. No longer am I at the mercy of shared hosts :)

      If your interested, I chose ServInt as my provider as they offered a great deal, as well as being a managed service (so I’m not on my own if I screw things up). I was tempted by the bells and whistles of Media Temple, but felt the ServInt service was better value.

    • Download Monitor 3.2.2 Maintenance Release

      Download Monitor has received some more love and has been updated. Here’s the change log from the new version:

      • Small bugfix in uploader.php – cat ID
      • Changed stats graph calculation – thanks lggemini
      • Changes to headers in download.php to avoid caching
      • File Browser fixes – $root was clashing with something….
      • exclude_cat works in all sections of download_page now
      • Removed hardcoding of /uploads/
      • Added action to download.php – should be able to use it to stop a download if you want – maybe limiting downloads per day or something? Whatever you want…
      • Made it so if you post new file on ‘edit’ screen, the post date is updated.
      • Fixed the ‘blank meta’ section which blanks out custom field values when nothing is set.
      • Moved ‘allow_url_fopen’ check.
      • Someone said downloads don’t work with spaces in the name. They do! Wasting my time sonny…
      • All work and no play make jolley a dull boy
      • Had to rename capabilities so they work. Apologies if you have to set this up again! Cheers to Mark Dingemanse.
      • {category_ID} custom format tag added. Useful if you want to send someone to its category on the DL page I guess. Also added {category_other} so when no category is set “other” is shown – this is because the download page can show an ‘other’ section if you want it to.
      • You can now manually edit the post date on the edit download screen.

      If you have edited capabilities for download monitor user permissions, you’ll have to again sorry! This is because I named them too long. Also, you should check your forced downloads still work because there was a logic error meaning they may not have been forced after-all…

      Enjoy.

    • Mahousive update to Download Monitor (3.2)

      Today I completed the update for the Wordpress Download Monitor Plugin – many tweaks, fixes, and features added. There were no changes to the database structure so people upgrading should be fine. Here is the list from the change log:

      • {user} tag added for custom formats
      • ‘autop’ option fix
      • Download page buttons applied with CSS so they are easier to customise/translate.
      • Fix for pagination bug after editing a download
      • Category output fix on edit downloads screen
      • Category urls on download page use ID rather than name to prevent errors when cats have the same names.
      • exclude_cat added to download_page shortcode
      • Localised ‘hits’ ‘date’ ‘title’ on download page
      • Option to disable the download logging
      • Read file ‘chunked’ some people found large files were corrupted so this should help (fingers crossed)
      • Added show_tags option to download page – displays x amount of tags on the download page.
      • File Browser root setting and download.php logic/mime types modified thanks to Jim Isaacs (jidd.jimisaacs.com)
      • Interface Improvements
      • Bulk edit categories, custom fields, tags, member only downloads
      • Added roles for download monitor admin – should be able to use with a role manager plugin if you want anyone other than admin to access the admin section e.g. http://wordpress.org/extend/plugins/capsman/
      • Change redirect after add
      • Edit Cat names/parents
      • Dedicated tags and thumbnails fields (they still use meta table though)

      And yes, those category link bugs are fixed at long last, and you can edit category names finally. Phew!

    • Wordpress Spam Stopper Plugin Updated

      Spam stopper has been updated to v3.1 – and most of it has been recoded. Here’s the full list of changes:

      • Added changelog to readme.
      • Email validation bug squashed
      • Cached comments now work; if user forgets to fill in antispam or makes a mistake (and the JS does not catch it) the users comment will not be lost.
      • Redone entire code to make it more efficient
      • Admin section added for changing the antispam question
      • Form ID and honeypot trap added to form
      • Fully localized

      You can get the plugin from wordpress.org: http://wordpress.org/extend/plugins/spam-stopper/

      For support, please keep my comments clean and post on either the wordpress forums or my forum.

      To help support spam-stopper you can make a donation (buy me a coffee, or several) or rate it on wordpress.org. Thanks!