我想动画我点击一个按钮。它有类.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的 –