JQuery Slider - 滑动后调用函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/437588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:08:50  来源:igfitidea点击:

JQuery Slider - Call function after slide

jqueryajaxslider

提问by Ryan Smith

I have a JQuery silder that I'm using to set the score on a web application. I orignally had it so that the user clicked a submit button, but the client now wants it to update AJAX style.

我有一个 JQuery silder,用于在 Web 应用程序上设置分数。我最初拥有它以便用户单击提交按钮,但客户端现在希望它更新 AJAX 样式。

This would work find, but the slide function gets call on every movement, so my AJAX script will send a score before the slider has finished being moved.

这可以找到,但是每次移动时都会调用滑动函数,因此我的 AJAX 脚本将在滑块完成移动之前发送分数。

Is there a function on the JQuery slider that gets called on release of the slider? Is there a straight forward way for me to check to see when the slider has been released?

JQuery 滑块上是否有在滑块释放时调用的函数?有没有一种直接的方法可以让我检查滑块何时被释放?

Thanks,.

谢谢,。

回答by FryGuy

After a quick perusal of the source code, I would say to try using 'stop' or 'change' instead of 'slide.' It seems that the 'stop' event happens on mouseup, and the 'change' event happens on mouseup but only if the value changed. I didn't see any documentation on this, of course, I didn't look very hard.

快速阅读源代码后,我会说尝试使用“停止”或“更改”而不是“幻灯片”。似乎 'stop' 事件发生在 mouseup 上,而 'change' 事件发生在 mouseup 上,但前提是值发生了变化。我没有看到任何关于此的文档,当然,我看起来不是很努力。

回答by Salty

When initializing the slider, use this:

初始化滑块时,请使用:

var slider = $('.slider').slider({ 
    steps: 10,
    handle: $('.knob'),
    animate:'true',
    min:1,
    max:10,
    startValue: 1,
    change: function(e,ui){
        //Do something with ui.value
    } 
});

回答by Stobor

The documentation confirms what FryGuy just said... From the slider options page:

文档证实了 FryGuy 刚刚所说的话...... 从滑块选项页面:

change Function(Event, ui): Function that gets called on slide stop, but only if the slider position has changed.

stop Function(Event, ui): Function that gets called when the user stops sliding.

change Function(Event, ui):在滑动停止时调用的函数,但仅当滑块位置发生变化时才调用。

stop Function(Event, ui):当用户停止滑动时调用的函数。