jeudi 21 juillet 2016

Animation in sequence in JQuery

i wrote this code to make some animations, and it is working perfectly:

    for (var i = 0; i < $("div[id$='-1']").length; i++) {
            $("div[data-order="+ i +"]").css({opacity: 0, visibility: "visible"}).animate({
                top : '0%',
                opacity: 1 
            }, {
                duration : 800,
                easing : 'linear'
            });
    };

but when i wanted to display it in order with some delay with setTimeout it doesn't work any more!

    for (var i = 0; i < $("div[id$='-1']").length; i++) {
        setTimeout(function() {
            $("div[data-order="+ i +"]").css({opacity: 0, visibility: "visible"}).animate({
                top : '0%',
                opacity: 1 
            }, {
                duration : 800,
                easing : 'linear'
            });
        }, 1000);
    };

Aucun commentaire:

Enregistrer un commentaire