2011-11-21 62 views
2

爲什麼RaphaelJS(2.0.0)中的這個事件處理程序直接運行,而不是當您點擊它時?爲什麼RaphaelJS中的這個事件處理程序直接運行?

function enlarge (shape) { 
    shape.animate({'transform' : 's2'}, 200); 
} 

jQuery(function() { 
    var paper = Raphael("canvas", 1000, 1000); 
    var button = paper.circle(300, 50, 20); 
    button.attr({'fill':'black'}); 

    var circle = paper.circle(50, 50, 20); 
    circle.attr({'fill':'red'}); 

    button.mousedown(enlarge(circle)); 
}); 
+1

據透露,如果更換'的jQuery(函數(){'和'的jQuery(函數($){'你可以使用'$'那個函數內不得不一直編寫'jQuery'(即使在你的情況下,因爲你沒有使用它而沒有關係) – ThiefMaster

回答

3

.mousedown()期望函數引用作爲其參數。相反,你是一個函數調用,所有.mousedown()得到的參數是undefined。由於您需要通過circleenlarge(),因此無法直接傳遞對enlarge的引用。相反,包您來電enlarge()的功能:

button.mousedown(function() { 
    enlarge(circle); 
}); 
3

因爲你電話它立竿見影。

與此代碼替換button.mousedown(enlarge(circle));

button.mousedown(function() { 
    enlarge(circle) 
}); 
相關問題