jQuery滑块“滑动”事件:如何确定用户的滑动方向? [英] jQuery slider "slide" event: How do I determine the user's slide direction?
问题描述
我一直在用萤火虫解剖事件和ui对象,但它似乎没有任何我可以使用的东西。我错过了什么吗?我想我可以跟踪价值变化,但这看起来像是一个kludge。
I have been dissecting the event and ui objects in firebug but it doesn't seem to have anything I can use. Am I missing something? I suppose I can keep track of the value changes but that seems like it would be a kludge.
$(".selector").slider({
slide: function(event, ui){
// I need to tell if the slide is left-to-right or right-to-left here.
}
});
谢谢!
Jason
Thanks! Jason
推荐答案
如果你想获得方向(值减少或增加),只需使用开始和幻灯片事件。触发start事件时,将初始值存储在变量中。之后只需将此存储值与滑动事件创建的值进行比较。
If you want to get the direction (value decreases or increases) just use the start and slide event. Store the inital value in a variable when the start event is fired. After that just compare this stored value against the value the sliding event creates.
只需合并不同的事件。
编辑前:
使用记录 getter
var orientation = $( ".selector" ).slider( "option", "orientation" );
此选项确定
滑块是否具有最小值左边,右边的
max或者底部
底部的最小值,顶部的最大值。可能的
值:'水平','垂直'。
This option determines whether the slider has the min at the left, the max at the right or the min at the bottom, the max at the top. Possible values: 'horizontal', 'vertical'.
这篇关于jQuery滑块“滑动”事件:如何确定用户的滑动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!