简体   繁体   English

jQuery UI更改滑块句柄宽度?

[英]Jquery UI change slider handle width?

I would like to make the handle of my slider scale to give a visual que of the range of the slider (like the scrollbar in most browsers for example). 我想使滑块的比例缩放以提供滑块范围的可视化提示(例如,大多数浏览器中的滚动条)。

Did a bit of googling and the answer seems to be to modify the .ui-slider-handle class. 做了一些谷歌搜索,答案似乎是修改.ui-slider-handle类。

I have done this and the handle now runs way off the end: 我已经完成了此操作,并且句柄现在结束了: 例 This is the code I am using to set up the slider: 这是我用来设置滑块的代码:

var range = 2 + Math.floor(Math.random() * 10);

$('#slider').slider({max: range});

$('.ui-slider-handle').width($('#slider').width() / range);

Also here is a link to live example: http://tcusers.com/examples/6473423467/example.html 另外,这里还有一个实时示例的链接: http : //tcusers.com/examples/6473423467/example.html

It's as if the library is assuming the old width of the slider, does anyone have any suggestions to accomplish what I want? 好像库假设滑块的宽度是旧的一样,有人对我想要的东西有什么建议吗? I'd rather avoid having to hack the jquery ui core library. 我宁可避免不得不破解jquery ui核心库。

Thanks in advance 提前致谢

The problem is in the core of the slider. 问题出在滑块的核心。 To move it jQueryUI changes its "left" style from 0% to 100%. 为了移动它,jQueryUI将其“左”样式从0%更改为100%。 The original slide also goes beyond the end, but you dont notice because its a narrow one. 原始幻灯片也结束了,但是您没有注意到,因为它是狭窄的。 Doing it wider you really start to notice that it starts growing begining at 100% of left... 扩大范围,您真的开始注意到它开始从左侧的100%开始增长。

As you can read here: http://bugs.jqueryui.com/ticket/4398 , there is no built-in solution. 如您在这里所读: http : //bugs.jqueryui.com/ticket/4398 ,没有内置解决方案。

But they point to a solution that: This is done by setting the margin-left variably (between 0 and handle-width) as the handle slides from slider min to slider max. 但是,他们指出了一种解决方案: 通过在手柄从滑块min滑动到滑块max时可变地设置左边距(在0和手柄宽度之间)来完成此操作。

Here: http://jquery-ui.googlecode.com/svn/trunk/demos/slider/side-scroll.html 此处: http : //jquery-ui.googlecode.com/svn/trunk/demos/slider/side-scroll.html

More info on the subject: 有关此主题的更多信息:

http://osdir.com/ml/jquery-ui/2009-03/msg00886.html http://osdir.com/ml/jquery-ui/2009-03/msg00886.html

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

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