无需不断地查询 DOM。将 存储$('.grower')
在一个变量中:
$(document).ready(function() {
var $grower = $('.grower');
function runIt() {
$grower.animate({
width: "30px",
height: '30px',
left: "-6",
top: "-6",
opacity:"0"
}, 800, function() {
$grower.removeAttr("style");
runIt();
});
}
runIt();
});
这是小提琴:http: //jsfiddle.net/jC8Js/
更新:如果您希望它在每个周期之前暂停,请使用计时器:
setTimeout(runIt, 1000);
这是小提琴:http: //jsfiddle.net/jC8Js/1/
或者,您可以使用间隔计时器运行所有这些:
$(document).ready(function() {
var $grower = $('.grower');
setInterval(function() {
$grower.animate({
width: "30px",
height: '30px',
left: "-6",
top: "-6",
opacity:"0"
}, 800, function() {
$grower.removeAttr("style");
});
}, 1500);
});
这是小提琴:http: //jsfiddle.net/jC8Js/2/