私はちょうどjQueryanimate()で遊んでいました。ある種の無限のスクロール背景を作成しようとしました(ここでフィドル)。しかし、私の人生では、スムーズな移行を理解することはできません。ここに投稿されたコード-
HTML
<div class='bg r hide'></div>
<div class='bg g hide'></div>
<div class='bg y hide'></div>
<div class='bg b hide'></div>
JavaScript
var backgroundTimeout = 1700;
function animateMotion(){
$('.bg').each(function(i, item) {
var self = $(this);
setTimeout(function() {
self.css('opacity', '0.5').removeClass('hide')
.animate({opacity: 1, marginLeft: '+=6'}, backgroundTimeout / 3)
.animate({
marginLeft: '+=30',
opacity: 0,
queue: false,
}, backgroundTimeout + 400, 'linear', function() {
self.css('marginLeft', 0);
self.css('opacity', 1);
self.addClass('hide');
})
if (self.index() === $('.bg').length - 1) {
setTimeout(animateMotion, backgroundTimeout);
}
}, backgroundTimeout * i + 1)
});
}
私がしようとしていること-1番目のdivが移動します-フェードアウトします-フェードアウトの途中です-次のdivがフェードインし、サイクルを再開します。私が間違っているアイデアはありますか?