admin管理员组文章数量:1399339
I have a bootstrap slider on my page. I don't know how can I change this code, that the page.php will not be constanly loading while dragging the slider, but only when I stop dragging it (after the desired period of time). Probably I have to use slideStop event, but don't know how.
<script type="text/javascript">
$(document).ready(function() {
var intSeconds = 1;
var refreshId;
function sTimeout() {
$("#mydiv").load("page.php"); // load content
refreshId = setTimeout(function() { // saving the timeout
sTimeout();
}, intSeconds *3000);
}
sTimeout();
$.ajaxSetup({cache: false});
// The slider
$("#ex1").slider({
min : 1, // minimum value
max : 20, // maximum value
step : 1,
value : intSeconds, // copy current value
formater: function(value) { // option to format the values before they are sent to the tooltip
clearTimeout(refreshId); // clear it
intSeconds = value; // update value
sTimeout(); // restart it
return value*3 + ' s';
}
});
});
</script>
I have a bootstrap slider on my page. I don't know how can I change this code, that the page.php will not be constanly loading while dragging the slider, but only when I stop dragging it (after the desired period of time). Probably I have to use slideStop event, but don't know how.
<script type="text/javascript">
$(document).ready(function() {
var intSeconds = 1;
var refreshId;
function sTimeout() {
$("#mydiv").load("page.php"); // load content
refreshId = setTimeout(function() { // saving the timeout
sTimeout();
}, intSeconds *3000);
}
sTimeout();
$.ajaxSetup({cache: false});
// The slider
$("#ex1").slider({
min : 1, // minimum value
max : 20, // maximum value
step : 1,
value : intSeconds, // copy current value
formater: function(value) { // option to format the values before they are sent to the tooltip
clearTimeout(refreshId); // clear it
intSeconds = value; // update value
sTimeout(); // restart it
return value*3 + ' s';
}
});
});
</script>
Share
Improve this question
asked May 29, 2014 at 16:14
DriverDriver
1991 gold badge1 silver badge11 bronze badges
1 Answer
Reset to default 4OK I'm gonna give this a try. I guess you are using the bootstrap slider plugin/add-on https://github./seiyria/bootstrap-slider or a similar fork.
So what you would want to do is to firstly cancel the setTimeout
on slideStart
and reinstate it on slideStop
. However if an ajax request started before the slider was moved and returns during drag you also don't want to update the contents of the div.
The code would go a little like this:
Javascript:
$(document).ready(function () {
var intSeconds = 1;
var refreshId;
//set a flag so we know if we're sliding
slideStart = false;
$('#ex1').slider();
$('#ex1').on('slideStart', function () {
// Set a flag to indicate slide in progress
slideStart = true;
// Clear the timeout
clearInterval(refreshId);
});
$('#ex1').on('slideStop', function () {
// Set a flag to indicate slide not in progress
slideStart = false;
// start the timeout
refreshId = setInterval(function () { // saving the timeout
sTimeout();
}, intSeconds * 3000);
});
//Change the sTimeout function to allow interception of div content replacement
function sTimeout() {
$.ajax({
url: 'page.php',
dataType: 'html',
success: function (response) {
if (slideStart) {
// slide in progress so bail out.
return;
} else {
// slide not in progress so go ahead.
$("#mydiv").html(response);
}
},
error: function () {
// handle your error here
}
});
}
refreshId = setInterval(function () { // saving the timeout
sTimeout();
}, intSeconds * 3000);
});
本文标签: javascriptBootstrap slider with slideStop eventStack Overflow
版权声明:本文标题:javascript - Bootstrap slider with slideStop event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744121851a2591776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论