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 2 3 ... 13
  1. Will says:

    So this is what you’ve been up to. hehe. I wondered where you’d gone Mike! :D .

    On a more serious note this looks pretty interesting, and Im sure its going to be another popular download. :D .

    Comment made on September 25, 2007 at 6:59 pm

  2. Mike Jolley says:

    lol thanks. Had (and still got) a lot on my plate, so i’ve been busy busy busy.

    Just uploaded newer version, removed some functions that were un-needed.

    Comment made on September 25, 2007 at 9:32 pm

  3. Torgil says:

    Looks very promising!
    Is it possible to run multiple instances with different corner settings specified?
    And if so, how to go about it?

    Comment made on September 26, 2007 at 1:39 pm

  4. Chris Pugsley says:

    Does this support the passing of parameters like the original curvy corners (ie corner radius)?

    Comment made on September 27, 2007 at 12:21 pm

  5. Mike Jolley says:

    Torgil and Chris: Yes you can, see the post; Ive updated with an example.

    Comment made on September 27, 2007 at 2:03 pm

  6. Bunker says:

    Hey, tried the example page with safari 3.0.3 and it displayed some funny behaviour, the CC script works fine with the same safari.

    Since I know jQuery doesn’t always plays nice with safari it could be that it is jQuery related and not your code.

    I just thought I’d mention it.

    You can find a screenshot at http://www.achter.be/cuvvycorners.png.

    Greetz

    Comment made on September 30, 2007 at 10:49 pm

  7. Diseño Web Chile says:

    Promising enough, we will test it

    Comment made on October 1, 2007 at 5:23 am

  8. Paul says:

    Looking forward to such a plugin. jQuery is the bomb. However, Safari is having issues with this plugin. In examples where all 4 corners are rounded, the inner corner background color does not apply – setting a background color on the entire html body will show through in those areas.

    In examples where top left and bottom right corners are set, the entire background color of the top and bottom areas is not applied.

    The lack of background compounds the issues of the ’sans-border’ example since there is not border line color to designate where the background color is missing – though it appears that it’s the entire top and bottom area as well.

    Thoughts?

    Comment made on October 2, 2007 at 2:24 pm

  9. Paul says:

    screenshot on win safari: http://www.pjms.net/clients/jQcurvySS.gif

    mac version looks the same…

    Comment made on October 2, 2007 at 2:30 pm

  10. Paul says:

    Oops, it seems the mistake was mine – i extricated the inline css code and put it in a style tag – but outside of the head element. Once i put the style stuff in the head element where it belonged, all is right with safari once more. Plugin doesn’t seem to work at all with external css however…

    Comment made on October 2, 2007 at 5:52 pm

  11. Jacques says:

    I confirm the funny behavior in Safari 3.03.

    Comment made on October 3, 2007 at 7:48 am

  12. schnuck says:

    doesn’t work in safari 2.x either. white squares at all four corners.

    Comment made on October 3, 2007 at 8:54 am

  13. joeri says:

    Does it work on top of div’s that have a background image?

    Comment made on October 3, 2007 at 1:33 pm

  14. visitor says:

    is there an xhtml strict version withuot inline styles?

    Comment made on October 4, 2007 at 4:33 am

  15. malsup says:

    Very nice work, Mike!

    Comment made on October 4, 2007 at 12:20 pm

  16. fxencore says:

    Its nice, but I think the solution with images is better because not every browser display this javascript correctly.

    Comment made on October 8, 2007 at 10:14 am

  17. Lau says:

    Argh crap… push ctrl+r by accident just as I was finishing up my replay :/ Oooh well, here we go again.

    Anyway, great stuff you’ve got going here. Love jQuery and rounded corners ;-) But I ran into the same problem with Safari as mentioned above while playing with Adobe AIR (which uses the same web toolkit, WebKit, as Safari), so I decided to look into it.

    I found that the problem is in the drawPixel function in the if-statement at line 487 when called from line 168 “if(y1 > -1) this.drawPixel(…);”. It looks like the problem is that on Safari $(this.box).css(“backgroundImage”) returns undefined when the style is absent which results in the if-statement evaluating to true.

    I don’t know if this is a bug in jQuery (it’s a bit hard to find out what .css() is supposed to return), but a quick fix is to set this.backgroundImage to an empty string if it’s undefined:

    Line 30:
    - var backgroundImage = $(this.box).css(“backgroundImage”);
    + var backgroundImage = $(this.box).css(“backgroundImage”) || “”;

    While hunting down this bug I found another one in the CSS on line 490, it’s missing:

    “background-color”: colour

    The bug shows up when the background image has transparency near the corners.

    Hope this helps,
    Lau
    http://www.iola.dk

    Comment made on October 14, 2007 at 11:21 pm

  18. Angie says:

    I’ve tried up, down and backwards to get this plugin to round something and all I’m left with is a pile of hair next to my desk. Any clues would be greatly appreciated. I started with curvy corners and due to it being a bit slow loading, as well as my desire to keep with one library (jQuery), I have been trying multiple other options. So far, I just keep having to reinstall the original Curvy Corners because there is an issue with everything else. I was really excited and had very high hopes at making this one work. Especially since it was based off the one I am already using and have working perfectly. However, I can get no where with this. If someone could answer the following it would help greatly.
    1. Does the code work with earlier versions of jQuery or do I have to use 1.2+?
    2. Is the statement in the comments about the script not working at all with external css styles true? I didn’t even bother learning how to include styles in my header as I’m a strictly linked file kinda gal, this comment is the only thing I have been able to conclude may be the culprit.

    3. I copied the code straight off the example page and still it wouldn’t render any curves. The styles are not in the header in that source code, so the above mentioned comment is even more confusing.

    3. Due to the fact that I have to run jQuery in no conflict mode, I have to adjust the document ready call to: jQuery(function($) { or it won’t play nice with other javascript libraries, could this be of relevance?

    Comment made on October 21, 2007 at 6:09 am

  19. Mike Jolley says:

    @Angie – First things first, install firebug extension for firefox. It will inform you of any JS errors.

    1 – Only tested 1.2

    Comment made on October 21, 2007 at 9:27 pm

  20. Lau says:

    It seems there’s a problem with background images in Firefox. The bottum fill-part is the color of the top edge of the image. I’m experiencing this problem when putting in a gradient as background.

    Comment made on October 22, 2007 at 1:33 pm

  21. elvisparsley says:

    I tried to put for this for vertical navigation, but it does not work in IE7. Is there anyone who can help me?

    Comment made on October 30, 2007 at 4:35 pm

  22. ben says:

    Was having problems with IE7 clear text, bold fonts were looking aliased in a bad way. There’s a corrective measure on line 469 that can be modified if anyone else encounters the issue.

    if(($.browser.msie) && ( $(this.box).css(“opacity”) ) )

    Was able to get anti-aliasing back by using the correction only when opacity was applied, I think this makes sense but alter at your own risk..

    if(($.browser.msie) && ( $(this.box).css(“opacity”) < 1 ) )

    hope this helps.

    Comment made on November 21, 2007 at 5:19 pm

  23. ben says:

    regarding last comment, here’s slightly safer logic.

    (($.browser.msie) && ( $(this.box).css(“opacity”) ) && ( $(this.box).css(“opacity”) < 1 ) )

    Comment made on November 21, 2007 at 5:31 pm

  24. Mike Jolley says:

    Uploading a new version to fix some bugs in ie7 etc, I even found a logic bug that the original plugin had!!!

    Comment made on November 22, 2007 at 12:29 am

  25. Jukka-Pekka Keisala says:

    Is it possible to add gradient image lets say that on the top there would be #ccc and bottom #eee.
    Can I somehow add gradient #ccc -> #eee in the middle?

    Comment made on November 25, 2007 at 1:14 pm

1 2 3 ... 12

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

    • @AzN102 If you mean the social link, you need to create a page called 'social' and give it the template called 'home'.
  • Out of the blue - More

    • MiniCard 1.1.7 Update

      I have just uploaded 1.1.7 of MiniCard here and to the WordPress theme directory. This updates includes:

      • New networks; xing, gowalla, yelp, foursquare, mobileme, google buzz
      • A way to change link text and define multiple links of the same network
      • A way to define your own custom links + icons
      • Improved admin panel

      Hope you like it, and don’t forget you can show your support by purchasing the premium pack from here.

    • 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!