我想動畫我點擊一個按鈕。它有類.testclass。我有一個以上的名稱的按鈕,這就是爲什麼我需要指定正確的。爲什麼「這個」在這裏不起作用?jQuery點擊並動畫這
問題是我需要在函數中調用「this」,因爲我想要一個動畫循環。
的CoffeeScript:
$('.testclass').click ->
colorFader = ->
$(this).animate
backgroundColor: '#33e27d', 1000, 'linear', ->
$(this).animate
backgroundColor: '#27ae60', 1000, 'linear', colorFader
colorFader()
OK,在JavaScript就應該是這樣的:
$('.testclass').click(function() {
var colorFader;
colorFader = function() {
return $(this).animate({
backgroundColor: '#33e27d'
}, 1000, 'linear', function() {
return $(this).animate({
backgroundColor: '#27ae60'
}, 1000, 'linear', colorFader);
});
};
return colorFader();
});
什麼OP是使用被稱爲CoffeeScript的 –