jQuery动画触发.complete回调5次
jQuery animate triggers .complete callback 5 times
看不出我的错。请帮忙弄清楚为什么动画触发器回调了好几次。
从上到下滚动文本块下面的代码。"step" of animate移动自定义滚动条…
currentText.stop().animate({
top: "-"+textHeight+"px"},
{
duration: durationOfAutoScroll,
step: function(currentTop) {
var positionY = currentTop;
if (positionY < curState.maskHeight - curState.textHeight) positionY = curState.maskHeight - curState.textHeight;
if (positionY > 0) positionY = 0;
var scrollPosition = -positionY * curState.scrollHeight / (curState.textHeight - curState.maskHeight);
curState.scrollerTop = scrollPosition;
$(".news-text .scroll-bar .scroller").css("top", scrollPosition);
},
complete: function() {
//jQuery.dequeue(currentText);
currentText.attr("data-state", 0);
onEndScroll();
}
}
);
这意味着你的集合(currentText)有5
元素,每个元素触发一次回调,这是预期的行为。
如果这不是你想要的,你可以创建一个promise对象并使用done
方法:
currentText.stop().animate({
top: "..."
}, {
duration: '...',
step: function () {
// ...
},
}).promise().done(function () {
// done
});
相关文章:
- 当我的单元测试失败时,回调被调用了两次
- $watch回调每次在浏览器中触发,但在测试期间只触发一次
- Jquery回调函数执行多次
- Iframe 加载回调被多次调用
- Bootstrap3确认模式回调触发两次
- 在多次AJAX调用后暂停执行AJAX回调
- 在第一次错误回调时退出承诺链
- 何时应该使用错误第一次回调
- 如何在jQuery中只对多个事件触发一次回调
- 正则表达式回调函数只执行一次
- 回调函数在引导模态上调用两次甚至更多次
- 从节点 js 异步函数进行多次回调
- 防止动画多次运行 - js 回调
- 回调函数不会在使用 $timeout 的服务中只调用一次
- 第二次调用主干时在回调中丢失上下文
- 回调-第二次回调后出错
- 为什么$watchGroup称之为's回调两次
- jQuery动画在运行时触发回调两次
- jQuery动画触发.complete回调5次
- 执行jquery $.when()的done回调一次(在backbone-js应用中)