【发布时间】:2017-08-18 12:33:19
【问题描述】:
我正在使用以下函数来为幻灯片制作动画,就像 slideUp() 或 slideDown():
(function($) {
jQuery.fn.slideLeftHide = function(speed, callback) {
this.animate({
width: "hide",
paddingLeft: "hide",
paddingRight: "hide",
marginLeft: "hide",
marginRight: "hide"
}, speed, callback);
}
jQuery.fn.slideLeftShow = function(speed, callback) {
this.animate({
width: "show",
paddingLeft: "show",
paddingRight: "show",
marginLeft: "show",
marginRight: "show"
}, speed, callback);
}
})(jQuery);
问题是,我想在动画结束后只调用一次函数。 我尝试这样做:
$(".item").slideLeftHide(function() {
$(this).remove();
}).done(function() {
$(".tab").each(function() {
$(this).attr('data-status', 'success');
});
});
当我执行此代码时,我收到一条错误消息,指出 Cannot read property 'done' of undefined。 .then() 而不是 .done() 也会发生同样的情况。
我该如何解决这个问题?
谢谢!
【问题讨论】:
-
你没有返回承诺,所以不能使用 done/then,使用你传递的回调,即
$(".item").slideLeftHide(function() { $(this).remove(); $(".tab").each(function() { $(this).attr('data-status', 'success'); }); })
标签: javascript jquery jquery-animate deferred custom-function