views:

1573

answers:

2

You may have seen Javascript sliders before:

http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.slider.html

What I'm envisioning is a circular slider. It would consist of a draggable button at one point on the circle -- and that button can be dragged anywhere along the ring. The value depends on what position the button is at (think of a clock).

This is obviously a lot easier said than done. Could someone please guide me in the right direction of how to accomplish this?

+1  A: 

define a center point c current mouse point at m

in your mouse drag event handler, you'd have

var dx = m.x-c.x;
var dy = m.y-c.y;

var scale = radius/Math.sqrt(dx*dx+dy*dy);

slider.x = dx*scale + c.x;
slider.y = dy*scale + c.y;

radius would be some preset value of the slider,

Jimmy
how would you implement this I was looking for the same thing and found this thread but I have no idea how I would implement that code
mcgrailm
same question math is plenty easy, but how would you implement the frontend? how do you structure this using div's and such?
ina
use css top,left on the element: example at http://pastebin.com/kTAfEwTC
Jimmy
A: 

How about this: http://www.thewebmasterservice.com/dev-blog/curved-rounded-or-circular-sliders-javascript-jquery-ui

Some explanations and a demo.

dRock