[英]Displaying Animation Effect on slider's value
I am using jQuery UI slider. 我正在使用jQuery UI滑块。 Is there any way to display current animated slider value if I click on any slider-range? 如果我点击任何滑块范围,有没有办法显示当前的动画滑块值?
Currently, the slider value doesn't get animated while the slider is 'sliding', provided slider's animate: true;
目前,滑块是'滑动'时,滑块值不会动画,只要滑块是animate: true;
For example: 例如:
It just changed from 0 to 20 instead of 0->1->2->3->4->5->6 ... ->19->20. 它只是从0变为20而不是0-> 1-> 2-> 3-> 4-> 5-> 6 ... - > 19-> 20。 (Animation effect on changed value). (动画对更改值的影响)。 Which is similar to this web's slider: Slider Example . 这类似于这个网页的滑块: 滑块示例 。 Anyone can do this? 任何人都可以这样做?
I think your wanting to have the Slider Button move to and from different parts of the Slider Bar with Numeric Updates seen on the webpage. 我想你想让Slider Button移动到Slider Bar的不同部分,并在网页上看到数字更新 。
This jsFiddle does that, as well as animates the Button automatically when a preset value is clicked on. 这个jsFiddle可以实现这一点,并且在单击预设值时自动为Button设置动画。
EDIT: Per your recent requirements via clarified example, here's a better method that achieves the same thing using already known values ... no need to calculate using expensive JavaScript Math.ceil()
. 编辑:根据你最近的要求,通过澄清的例子,这是一个更好的方法, 使用已知的值实现相同的事情......不需要使用昂贵的JavaScript Math.ceil()
计算。
The bonus is that the known percentage is provided as a floating point value which can make a difference on how it's to be used or if there are markers/hotspots on top/bottom of the Slider Bar. 奖励是已知百分比作为浮点值提供,这可以改变它的使用方式或滑块条顶部/底部是否有标记/热点 。
Check My Solution on animated slider value . 在动画滑块值上选中我的解决方案 。 Credited @arttronics as I updated my solution on top of his jsFiddle . 当我在他的jsFiddle上更新我的解决方案时, 归功于@arttronics 。 :) :)
Try to click on the slider bar to see the value get animated. 尝试单击滑块以查看值动画。 :) :)
I believe you just need to add the animate property to the slider. 我相信你只需要将animate属性添加到滑块。 For example: 例如:
$( "#slider-range-max" ).slider({
range: "max",
min: 1,
max: 100,
value: 1,
animate: true,
slide: function( event, ui ) {
$('#amount').val(ui.value);
}
});
Here is jquery UI slider example: 这是jquery UI滑块示例:
http://jqueryui.com/demos/slider/#multiple-vertical http://jqueryui.com/demos/slider/#multiple-vertical
If you are referring to the jQuery UI slider, try: 如果您指的是jQuery UI滑块,请尝试:
$('div#foo')
.slider({
animate: true,
slide: function(event, ui) {
$('div#bar').text(ui.value);
}
});
I found this code somewhere on the web (can't remember who to give credit) when I had a need to show the animation effect on increasing and decreasing numbers: 当我需要在增加和减少数字时显示动画效果时,我在网络上的某个地方找到了这个代码(不记得是谁给予信用):
var num_holder = $('#foo');
$({ someValue: 0 }).animate({
someValue: 100
}, {
duration: 1000,
easing:'swing',
step: function() {
num_holder.text(Math.ceil(this.someValue))
}
});
http://jsfiddle.net/cVndp/ http://jsfiddle.net/cVndp/
This is totally untested but perhaps it will work: 这是完全未经测试的,但也许它会起作用:
$('div#foo')
.slider({
animate: true,
slide: function(event, ui) {
$({ someValue: 0 }).animate({
someValue: ui.value
}, {
duration: 1000,
easing:'swing',
step: function() {
$('div#bar').text(Math.ceil(this.someValue))
}
});
}
});
You probably have to change the someValue
from 0 to whatever the previous place's value was. 您可能必须将someValue
从0更改为上一个值的值。 And also change the direction of the animation depending on which way the slider is being pulled, but it's a starting point. 并且还根据滑块的拉动方式改变动画的方向,但这是一个起点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.