2012-01-27 80 views
0

有人可以告訴我如何添加緩存到這個插件。我知道有一個緩動插件,yada yada,我只想讓這個插件在使用時可以選擇添加緩動和回調。我試過在speed,之後加上easing這個詞,所以它看起來像speed, easing, callback,但由於某種原因,它不起作用?添加easing到一個簡單的小jquery插件?不工作

jQuery.fn.animateAuto = function(prop, speed, callback){ 
    var elem, height, width; 
    return this.each(function(i, el){ 
     el = jQuery(el), elem = el.clone().css({"height":"auto","width":"auto"}).appendTo("body"); 
     height = elem.css("height"), 
     width = elem.css("width"), 
     elem.remove(); 

     if(prop === "height") 
      el.animate({"height":height}, speed, callback); 
     else if(prop === "width") 
      el.animate({"width":width}, speed, callback); 
     else if(prop === "both") 
      el.animate({"width":width,"height":height}, speed, callback); 
    }); 
} 

回答

1

應該是這樣:

 

el.animate(
    {height:your_height_value}, 
    speed, 
    'swing', //example easing here 
    complete: function() { //your callback, just an example 
    //do something 
    } 
); 
 

您是不是要找這樣的事情

+0

完美,這就是我錯了,當我是動畫。 – 2012-01-27 06:52:30