Javascript 如何在我自己的jQuery插件中实现BeforeAnimate和afterAnimate回调?
假设这是我的插件:Javascript 如何在我自己的jQuery插件中实现BeforeAnimate和afterAnimate回调?,javascript,jquery,jquery-plugins,callback,closures,Javascript,Jquery,Jquery Plugins,Callback,Closures,假设这是我的插件: // writing the plugin (function($){ $.fn.myPlugIn = function(options){ defaults = { beforeAnimate : function(){}, afterAnimate : function(){} } options = $.
// writing the plugin
(function($){
$.fn.myPlugIn = function(options){
defaults = {
beforeAnimate : function(){},
afterAnimate : function(){}
}
options = $.extend(defaults, options);
//here is where I need help
options.beforeAnimate();
$(this).animate({'width':'1000px'},1000);
options.afterAnimate();
}
})(jQuery);
//using the plugin
$('#art2').myPlugIn({
beforeAnimate: function(){
$('#art1').animate({'width':'1000px'},1000);
},
afterAnimate: function(){
$('#art3').animate({'width':'1000px'},1000);
}
});
我应该如何重写此部分:
options.beforeAnimate();
$(this).animate({'width':'1000px'},1000);
options.afterAnimate();
为了一个接一个地获得3个动画调用。(即等待上一个已完成)来自jQuery:
完全功能
如果提供了完整回调函数,则动画完成后将触发完整回调函数这对于按顺序将不同动画串在一起非常有用。回调不会发送任何参数,但会设置为正在设置动画的DOM元素。如果对多个元素设置了动画,则每个匹配的元素执行一次回调,而不是对整个动画执行一次回调