We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,390 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to delay jquery animations

How do I delay an animation in jquery?
I have a <p> in to the page as soon as the page loads. I have another <p> that I want to slide in only after the first <p> finishes coming in, and then I want an image to move when that second <p> is in.
How do I do that? (Right now, they all come in simultaneously)
Here's my code:

$(document).ready(function()
        {
             $('p.title').animate({"left":"300px", 
                                    },1020);


            $('p.subtitle').animate({"left":"370px", 
                                    },1020);

            $('.logo').animate({left: '+=250', bottom: '+=200', height:'140'},1120);


         });

thanks!

3
Contributors
4
Replies
3 Days
Discussion Span
2 Months Ago
Last Updated
15
Views
suavedesign
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I added

.delay (2000)

which works for the image.
But it's not a solution for the second <p>, because I dont want it to be on the page at all when the page loads. If I do .delay, you see the text on the page already when the page loads.
I want it to be hidden, and then scroll in after two seconds.
How do I do that?

Thank you.

suavedesign
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If I'm not mistaking, jQuery's animate() function let's you specify a function to execute when the animation finishes. If you put a timeOut in that function that launches your second animation upon timeout, you should see what you want to see, I guess ^^.

minitauros
Posting Whiz
333 posts since Apr 2011
Reputation Points: 45
Solved Threads: 51
Skill Endorsements: 4

There is an option to call another function once the animation has completed.

.animate( properties [, duration ] [, easing ] [, complete ] )

Check out the docs on here http://api.jquery.com/animate/

pixelsoul
Master Poster
707 posts since Feb 2011
Reputation Points: 171
Solved Threads: 107
Skill Endorsements: 18

Quick example:

$('p.title').animate({"left":"300px", },1020,
function() {
    $('p.subtitle').animate({"left":"370px", },1020);
});

http://jsfiddle.net/pixelsoul/khjZq/

pixelsoul
Master Poster
707 posts since Feb 2011
Reputation Points: 171
Solved Threads: 107
Skill Endorsements: 18

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0756 seconds using 2.83MB