JQuery: creating a circular slider

You may have already seen JavaScript sliders:

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

What I represent is a circular slider. It will consist of a draggable button at one point in the circle - and this button can be dragged anywhere along the ring. The value depends on what position the button is in (think about the clock).

+5
source share
5 answers

define center point c current mouse point in m

in the mouse drag event handler, you will 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

will be some slider preset value,

+3
source

jQuery, / .

-

0

All Articles