【发布时间】:2014-05-22 19:18:05
【问题描述】:
我想为我点击的按钮制作动画。它有类.testclass。我有不止一个具有该名称的按钮,这就是为什么我需要指定正确的按钮。为什么“这个”在这里不起作用?
问题是我需要在函数中调用“this”,因为我想要一个动画循环。
咖啡脚本:
$('.testclass').click ->
colorFader = ->
$(this).animate
backgroundColor: '#33e27d', 1000, 'linear', ->
$(this).animate
backgroundColor: '#27ae60', 1000, 'linear', colorFader
colorFader()
好的,在 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();
});
【问题讨论】:
标签: jquery click jquery-animate this