2013-01-17 93 views
0

我很难试图构建这个jQuery插件。我遇到的部分是让自定义回调函数触发。jQuery插件帮助:自定义回调

 

    (function($, window, document, undefined) { 

     // Function options 

     var methods = { 
      init : function(options) { 
       return this.each(function(){ 
        methods.start(this, options); 
       }); 
      }, 
      start : function(el, options) { 

       // Attach animationstart to selector 

       $(document).on("animationstart", el, function(){ 
        options.start.call(); 
       }); 

      } 
     } 

     // Plug-in code 

     $.fn.plugin = function(options) { 

      if (methods[options]) { 
       return methods[options].apply(this, Array.prototype.slice.call(arguments, 1)); 
      } else if (typeof options === "object" || ! options) { 
       return methods.init.apply(this, arguments); 
      } else { 
       $.error("Method" + options + " does not exist in plugin"); 
      } 

     }; 
    })(jQuery); 


    // Attach to DOM object 


    $('img').plugin({ 
     'start' : function(){ 
      console.log('Animation started'); 
     } 
    }); 

任何人都可以帮我弄清楚为什么'开始'不会触发自定义回调函数吗?

+0

似乎没有触发文档的“animationstart”事件 –

+0

每当CSS3动画在DOM对象上启动时,都不会发生这种情况吗? – humdinger

+0

似乎没有:http://jsfiddle.net/zbtxE/ –

回答