jQuery: Creating a circular slider

后端 未结 4 1226
逝去的感伤
逝去的感伤 2021-02-10 06:27

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 c

4条回答
  •  醉梦人生
    2021-02-10 06:54

    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,

提交回复
热议问题