Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loop in javascript

function DC() {
    var elements = $(".panel");
    elements.first().fadeOut(1000, function() {
        $(this).insertAfter(elements.last());
        $(this).fadeIn(1000);
    });
}

$(document).ready(function() {
    var i =0;
    for (var i=0; i < 10; i++) {
        DC();
    };
});

I want DC() to loop 10 times, but it only looped once.

What did I do wrong?

like image 653
Xitrum Avatar asked Feb 28 '26 12:02

Xitrum


1 Answers

DC starts a fadeOut 10 times in a row. If you want your elements to fade out and back in 10 times then you should call DC as fadeIn's callback.

elements.first().fadeOut(1000, function() {
    $(this).insertAfter(elements.last());
    $(this).fadeIn(1000, DC);
});
like image 90
mpartel Avatar answered Mar 03 '26 02:03

mpartel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!