2016-04-27 44 views
1

試圖讓jQuery的.animate成一個函數,因此會佔用的空間更少,更容易讓我讀製作.animate功能

function anim(object, values, end) { // Problem with the "end" part 
    $(object).animate (values, { 
     duration: 1000, 
     quene: false, 
     specialEasing: {top: "easeOutQuad"}, 
     complete: function() end // <-- here 
    }) 
}) 

我試圖使像{結束}太多,但它會工作。也嘗試改變結束到一個不同的名字,但沒有工作。

回答

1

當您調用它時,您只需傳遞一個代表您的complete事件的函數。所以,你的anim()功能應該是這樣的:

// The end parameter is simply a function that will be mapped to your completion event 
function anim(object, values, end) { 
    $(object).animate (values, { 
     duration: 1000, 
     queue: false, 
     specialEasing: {top: "easeOutQuad"}, 
     // This will map the completion event to your function that was 
     // passed in 
     complete: end 
    }) 
} 

實際調用的函數,你只需要簡單的選擇傳遞給元素,一系列的值

anim('#your-element', { ... }, function(){ alert('Done!'); }); 
+0

目標哦,好,我認爲如果我輸入一個表格,它會自動接受它,但我猜不是 – Gensoki