简体   繁体   English

无限循环jQuery?

[英]Endless loop jQuery?

So I'm trying to make this fading background animation go on forever on the web page.所以我试图让这个褪色的背景动画在网页上永远持续下去。 How would I do this?我该怎么做? Here is the code:这是代码:

    $( document ).ready(function() {
    // Changing the background js code
    console.log('File Loaded! DELETE!!!');
    animate();
});
function animate() {
    window.setInterval(function(){    
    window.setTimeout(function(){
       $('.content').css('background-image','url(http://crondon.guko.co.uk/wp-content/uploads/2015/11/confetti.jpg)');$('.content').css('transition','background 1s linear');$('.content').css('-webkit-transition','background 1s linear');$('.content').css('-moz-transition','background 1s linear');$('.content').css('-o-transition','background 1s linear');
    },3000);
        $('.content').css('background-image','url(http://crondon.guko.co.uk/wp-content/uploads/2015/11/bride_groom_baronial_hall1.jpg)');$('.content').css('transition','background 1s linear');$('.content').css('-webkit-transition','background 1s linear');$('.content').css('-moz-transition','background 1s linear');$('.content').css('-o-transition','background 1s linear');
    },3000);
    animate();
    }

You don't use setTimeouts inside a setInterval.您不在 setInterval 中使用 setTimeouts。 I think you are looking for the functionality of setInterval.我认为您正在寻找 setInterval 的功能。 Take a look at https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval .看看https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval

A basic example (which repeats every 1000ms or 1 second) would be:一个基本示例(每 1000 毫秒或 1 秒重复一次)是:

setInterval(function() {
    // Code to repeat here
}, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM