在我的jquery插件,完成動畫後,我被稱爲「摧毀」功能兩次..任何一個糾正我錯誤,我做什麼?jquery動畫完成使用承諾調用兩次
功能:
;(function ($, window, document, undefined) {
$.fn.BackendProcess = function(){
var that = this;
destroy = function(){
console.log(arguments.callee.caller.toString());//consoling 2 times
}
that.bind("myEventStart", function(e) {
$(this).css({width:"500"});
});
that.bind("myEventEnd", function(e) {
setTimeout(function(){
$(that).animate({width :"100"},{
easing: 'swing',
duration:2000
}).promise().done(function(){destroy()});
})
});
return{
start:function(){
that.trigger("myEventStart");
},
stop:function(){
that.trigger("myEventEnd");
},
destroy:function(){
console.log("distroy starts");
}
}
}
})(jQuery, window , document);
$(".myButton").BackendProcess().start();
$(".myButton").BackendProcess().stop();
但它不會解決我的問題,原因是,當我開始我應該顯示事件結束preloader時,我需要顯示另一個元素可見。 – 3gwebtrain
工作正常。你能否提供一些線索來理解這裏究竟發生了什麼......? – 3gwebtrain
當然,基本上我們正在移除初始化的所有事件,它可以幫助我們移除重複的事件。 –