Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

jQuery animation cascade

Hi I have a site with a div containing three or more div. My div id (id="linguetta_next") is dynamic: I add dynamically more than a div inside it. I want that the div into the main div (linguetta_next) appear in cascade: the first appear, at the end the second appear, at the end the third appear.

This is my html:

<div id="linguetta_next">
                <div class="linguetta" id="linguetta_next1" style="margin-left:1%;">
                    <p class="tit_linguetta">azienda</p>
                </div>
                <div class="linguetta_small" id="linguetta_next2" style="margin-left:10%; margin-top:10px;">
                    <p class="tit_linguetta_small">staff</p>
                </div>
                <div class="linguetta_small" id="linguetta_next3" style="margin-left:10%; margin-top:10px;">
                    <p class="tit_linguetta_small">risorse umane</p>
                </div>
             </div>

I have tried in this mode but in this mode appear at the same time, how can I make a cascade effect?

function moveDiv(){
var menu2=$(".colCenter").find('#linguetta_next');
menu2.css('right',-300).css('position','absolute').css('z-index',1000);
menu2.animate({left:0}, 1000 );
}

Upvotes: 3

Views: 3656

Answers (3)

Jozzeh
Jozzeh

Reputation: 841

If possible, use the jquery cycle plugin : http://jquery.malsup.com/cycle/

It's very easy to set up and use. An example in your case can be seen at the beginner demos:

$('#linguetta_next').cycle({ 
    fx: 'scrollLeft' 
});

Upvotes: 0

Vishal
Vishal

Reputation: 1234

Use an animation effect using jQuery's .animate() as you'll need a callback to create a cascading effect, the callback will be called only after the initial animation is complete along with time of animation (optional); like:

$('#linguetta_next1').animate(function() {
    // do animation stuff
} , 1000, function() {
    // callback - effect to do after first is complete
});

Upvotes: 2

VisioN
VisioN

Reputation: 145398

Here is one option:

$("#linguetta_next div").each(function(i) {
    var el = $(this);
    setTimeout(function() {
        el.animate({
            left: 0
        }, 1000);
    }, i * 2000);
});​

DEMO: http://jsfiddle.net/5Pbwf/

Upvotes: 7

Related Questions