我想我對jQuery的瞭解足以讓我陷入困境。我有三個連續的動畫,我很滿意。但現在需要它們按順序運行並重復。我不確定排隊或settimeout。想想我只需要重寫和合並,但不確定最好的方法。 將我的代碼簡化爲JSFIDDLE。隊列單獨連續動畫,並按順序運行,而不是重複運行
$(document).ready(function() {
var $pulse = $('.a');
function runIt() {
$pulse.animate({margin:"0 0 0 150px",opacity:"1"}, 1100)
.animate({margin: "100px 0 0 150px",opacity:"0"}, 1400,
function() {
$pulse.removeAttr("style");
runIt();
});
}
runIt();
});
//
$(document).ready(function() {
var $pulse = $('.b');
function runIt() {
$pulse.animate({margin:"100px 0 0 150px",opacity:"1"}, 1100)
.animate({margin: "200px 0 0 150px",opacity:"0"}, 1400,
function(){$pulse.removeAttr("style");
runIt();
});
}
runIt();
});
//
$(document).ready(function() {
var $pulse = $('.c');
function runIt() {
$pulse.animate({margin:"200px 0 0 150px",opacity:"1"}, 1100)
.animate({margin: "300px 0 0 150px",opacity:"0"}, 1400,
function(){$pulse.removeAttr("style");
runIt();
});
}
runIt();
});
你可以在這裏發佈:HTTP:// codereview.stackexchange.com/ –