简体   繁体   English

jQuery:创建一个圆形滑块

[英]jQuery: Creating a circular slider

You may have seen JavaScript sliders before: 你可能以前看过JavaScript滑块:

http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.slider.html 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). 该值取决于按钮的位置(想想时钟)。

define a center point c current mouse point at m 在m处定义中心点c当前鼠标点

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, radius是滑块的某个预设值,

I have written a jQuery plugin which supports full/half circle sliders. 我写了一个jQuery插件 ,支持完整/半圆滑块。

Demo Page & Documentation 演示页面文档

Check the jQuery roundSlider plugin from here http://roundsliderui.com/ . 从这里http://roundsliderui.com/查看jQuery roundSlider插件。 This is what you want exactly. 这正是你想要的。

This roundslider having the similar options like the jQuery ui slider. 这个roundslider有类似jQuery ui滑块的选项。 It support default, min-range and range slider type. 它支持默认,最小范围和范围滑块类型。 Not only the round slider it also supports various circle shapes such as quarter , half and pie circle shapes. 不仅圆滑块它也支持各种圆形的形状 ,如季度半年饼形圈的形状。

For more details check the demos and documentation page. 有关更多详细信息,请查看演示文档页面。

Please check the demo from jsFiddle . 请查看jsFiddle的演示。

Related answers: https://stackoverflow.com/a/31367164/1845801 and https://stackoverflow.com/a/31369265/1845801 相关回答: https //stackoverflow.com/a/31367164/1845801https://stackoverflow.com/a/31369265/1845801

Screenshots: 截图:

jquery圆形滑块 - 不同的圆形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM