Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Creating a circular slider

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).

like image 696
Matt Avatar asked Oct 15 '22 17:10

Matt


1 Answers

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,

like image 86
Jimmy Avatar answered Oct 21 '22 09:10

Jimmy