Click here to Skip to main content
12,946,164 members (54,364 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello coders
My first week of using jquery, going well so far but met my first small hurdle.
I would like the div animation to finish before triggering the next function.
From what I have read I need to add a function after animate but when I try and adapt the code I end up with errors. I hope someone can solve this one for me. Thanks :)

$(document).ready(function() {
$('#slick2').click(function() {
Posted 8-Jun-10 5:46am
Updated 8-Jun-10 6:26am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You should use callback that will be called by jquery when the animation is complete:
$("#flash").animate({'width':'500px','height':'800px'},800, function() {
  // your code here: 
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Thanks for the fix Dmitry. It worked great.
I have made some alterations to my code. I am now triggering the javascript from a button inside a swf and have added another function 'scrollToTop'(last one honest) At the moment I have this...

function scrollToTop(){
$.scrollTo('0px', 600 );
var wait = setInterval(function() {
	if( !$("#element1").is(":animated") ) {
}, 200);

It works but looks messy to me, the downside is that '#flash animate' and 'main' are triggering at the same time. I would prefer the three functions to fire sequentially. Many Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 8 Jun 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100