有人可以請這個協助嗎?我顯然是一名新秀,因爲這並不難,但我無法弄清楚。這在4個背景圖像之間旋轉,我想要做的就是在第一個圖像(循環)重新開始並再次運行該函數。如何讓JQuery不斷循環
真的很感謝幫助!
$(document).ready(function(){
$(".wrapper").css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-1.jpg') %>)"
);
setTimeout(function(){
$(".wrapper").css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-1.jpg') %>)"
).fadeOut(function(){
$(this).css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-2.jpg') %>)"
).fadeIn();
});
setTimeout(function(){
$(".wrapper").css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-2.jpg') %>)"
).fadeOut(function(){
$(this).css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-3.jpg') %>)"
).fadeIn();
});
setTimeout(function(){
$(".wrapper").css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-3.jpg') %>)"
).fadeOut(function(){
$(this).css("background-image", "linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)), url(<%= asset_path('bg-4.jpg') %>)"
).fadeIn();
});
}, 3000);
}, 3000);
}, 3000);
});
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval – tier1