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 OriginalGriff 475
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 219
4 Mathew Soji 160
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.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