Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery
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 Smile | :)
 
<script>
$(document).ready(function() {
$('#slick2').click(function() {
$("#flash").animate({'width':'500px','height':'800px'},800);(pause/wait)
document.getElementById('main').height="800";
});
});
</script>
Posted 8-Jun-10 6:46am
Edited 8-Jun-10 7:26am
v2
Rate this: bad
good
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: 
  document.getElementById('main').height="800";
});
  Permalink  
Rate this: bad
good
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") ) {
		clearInterval(wait);
		$("#flash").animate({'width':'500px','height':'800px'},800);
		document.getElementById('main').height="800";
	}
}, 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
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Maciej Los 359
2 Kornfeld Eliyahu Peter 309
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 8 Jun 2010
Copyright © CodeProject, 1999-2014
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