2013-01-17 94 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/ –

回答