下面的链接用于复制jquery滑块,我想使滑动平滑但是当我减少setinterval中的时间(比如200)时,滑块不会立即响应mouseup事件并且幻灯片在一秒钟后停止或者触发mouseup后两次。 我也试过在jquery动画上使用stop,但这没有帮助。 链接在这里 。 http://jsfiddle.net/WwT54/ 现在每半秒后幻灯片移动10px,我想让它看起来很流畅。
$("#popUpInnerArrowLeft").mousedown(function (event) {
movetoleft();
});
var into, into2;
function movetoleft() {
function moveit() {
$(".thumbsInnerContainer").animate({
left: '-=10px'
});
}
into = setInterval(function () {
moveit();
}, 500);
}
$(document).mouseup(function (event) {
clearInterval(into);
});
//for the right arrow
$("#popUpInnerArrowRight").mousedown(function (event) {
movetoright();
});
function movetoright() {
function moveit2() {
$(".thumbsInnerContainer").animate({
left: '+=10px'
});
}
into2 = setInterval(function () {
moveit2();
}, 500);
}
$(document).mouseup(function (event) {
clearInterval(into2);
});
答案 0 :(得分:1)
检查一下(这就是你想要的):
var into, into2, unit = '';
$("#popUpInnerArrowLeft").click(function (e) {
e.preventDefault();
unit = false;
movetoleft();
});
//for the right arrow
$("#popUpInnerArrowRight").click(function (e) {
e.preventDefault();
unit = true;
movetoright();
});
function moveit() {
$(".thumbsInnerContainer").stop(true,true).animate({
left: ((unit == true)? '+=':'-=') + '10px'
},{easing:'linear'});
}
function movetoright() {
into = setInterval(function () {
moveit();
}, 300);
}
function movetoleft() {
into = setInterval(function () {
moveit();
}, 300);
}
$(document).mouseup(function (event) {
clearInterval(into);
});
在这里工作小提琴:http://jsfiddle.net/WwT54/2/