jQuery 3D Circle

Published Monday 12th of December 2011

I wanted to learn more about CSS 3D transforms so I started experimenting with the login page on SleekPHP.

It all turned into a jQuery Plugin called "3D Circle". I haven't uploaded it to the site yet but you can find both the CSS and the JS (beta) on Google code.

There's also a demo you can try out here (only tested in Chrome).

It's just a save of the HTML, CSS and JS on that page so you won't actually be able to sign up or do anything else. That's not the point of the demo though so.

I've only tried it in Chrome but use all vendor prefixes in the CSS so if your browser supports them all it should work in it too.

It took me a while to get everything the way I wanted it. The circle is automatically generated based on the items on the page. So if you add or remove items the circle adapts.

First I tried calculating the positions myself using sin and cos and apply them to the item's translateX and translateZ values. This worked fine before I started rotating the items as well. Without rotation the items were all facing the screen but they were at least in a circle.

When I started rotating the items all hell broke lose and nothing looked right. After some debugging I noticed that the rotation's origin is always from the 0, 0, 0 position. So the item would no longer rotate around itself but around the point at 0, 0, 0.

Thanks to this, though, it was much easier than having to calculate the circle positions myself. All I needed to do was place all the items at z: radie and then rotate them by 360 deg / num items.

Doing that placed all my items in a nice circle. Now to rotate this circle all I needed to do was rotate the parent element of all the items.

The problem with this, though, is that some items will be "in front" of the 0 z pane. That means they will look pretty much twice their size and that's not what we want.

My first thought was to simply move the wrapper of the items in the z pane, but doing that introduced the same problem I had before with the items themselves; now the rotation of the wrapper would go around its 0, 0, 0 position while it's sitting at 0, 0, -radie.

The only solution I could come up with was to wrap the circle in yet another element used only to move the circle in x, y or z.

So the final HTML requires quite a lot of wrapping elements. If you're doing this to a list of elements though you'll already have a ul and possibly a wrapping nav or section so you'd only need to add one extra element.

The outer wrapper is the "stage" for the circle. It contains the perspective and perspective-origin properties. Without these the transforms will all be flat.

The second wrapper is the "mover" for the circle. It is only used for moving the entire circle its radie in the z pane. This way we avoid having elements twice their size.

The third wrapper is the actual circle and its direct descendants are the circle items.

As you can see the demo is from SleekPHP's login page, you can check out SleekPHP's logger at the bottom of the page. I've got loads of other work atm so progress has been a bit slow lately.

Tags
Comments
No comments

Bookmark this Article

  • del.icio.us
  • Digg
  • Furl
  • Google
  • Technorati
  • Ma.gnolia
  • Blinklist
  • Blogmarks
  • Rojo
  • Stumbleupon

No Comments

No comments yet, why not be the first to post one?

Post a Comment

Random jQuery Plug-ins

  • Text Shadow

    Frankly a rather crappy text-shadow plug-in (can one be done well? :) but nevertheless it does the job in some cases.

    Details

  • Colour Picker

    Use this plug-in on a normal <select>-element filled with colours to turn it in to a colour-picker widget that allows users to view all the colours in...

    Details

  • Favicons

    This little plug-in will insert favicons to all external links found on your site. The plug-in scans the URL the link is pointing to for a favicon and...

    Details

More Plug-ins

Page cached. Loaded in: 0.2181 second(s).
Last DB change: 2012-02-19 09:46:01
Last file change: 2011-10-03 07:42:35
Cache created: 2012-02-23 00:33:55