How to make endless jquery repeat loop

I am trying to implement a jQuery infinte loop with images inside a div. I tried to do this with the setInterval function, but the fact is that the whole animation starts with a 3 second delay, and what I want to achieve is that the animation repeats by itself when it comes to the end after 3 seconds, I also tried to execute the callback function after .fadeTo, but it just applies to the first image, not the whole animation.

Here is the code:

setInterval(function(){
    $('#animation-text img').each(function(i) {
        $(this).delay((i++) * 500).fadeTo(70, 1);
    });
}, 3000);

And here is the jsfiddle: http://jsfiddle.net/cavoledeni/edo5vcnz/

Any ideas?

+4
source share
4 answers

Update: Demo 2

function setIntervalAndExecute(fn, t) {
    fn();
    return (setInterval(fn, t));
}

$(document).ready(function () {
    setIntervalAndExecute(function () {
        var $this = $('#animation-text img');
        $this.css({'opacity': 0});
        $this.each(function (i) {
            $(this).delay((i++) * 500).fadeTo(70, 1);
        });
    }, 3000);


});

Demo

. . ( ), type 0. type - opacity. .

function setIntervalAndExecute(fn, t) {
    fn();
    return (setInterval(fn, t));
}

$(document).ready(function () {
    var type = 1;
    setIntervalAndExecute(function () {
        $('#animation-text img').each(function (i) {
            $(this).delay((i++) * 500).fadeTo(70, type);
        });
        type = (type + 1) % 2;
    }, 3000);


});
+1

, , . ,

https://jsfiddle.net/Midhun52/zg40dgcs/

$(document).ready(function(){
var a=function(){
    $('#animation-text img').each(function(i) {
        $(this).delay((i++) * 100).fadeTo(900, 1);
    });
}


 var b=function(){
    $('#animation-text img').each(function(i) {
        $(this).hide()
    });
}
setInterval(a, 5000);
 setInterval(b, 8000);

});

+2

fadeOut() :

$(document).ready(function(){
    
    setInterval(function(){
        $('#animation-text img').each(function(i) {
            $(this).delay((i++) * 500).fadeTo(10,1);
        });
    }, 3000);
    setInterval(function(){
        $('#animation-text img').each(function(i) {
            $(this).delay((i++) * 500).fadeOut(10);
        });
    }, 8000);
});
  #animation-text { width: 100%; font-size: 0; border: 1px solid red; }
#animation-text img { opacity: 0; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
 <div id="animation-text">
		<img src="http://lorempixel.com/g/70/70/" alt="">
		<img src="http://lorempixel.com/g/70/70/" alt="">
		<img src="http://lorempixel.com/g/70/70/" alt="">
</div>
Hide result
+1

, . -

$(document).ready(function() {   
  function animateDivers() {
    $('#divers').animate({'margin-top':'90px'},6000).animate({'margin-  top':'40px'},6000, animateDivers); 
  }
  animateDivers();
}); 

jquery div,

0

All Articles