Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Wait till end of SlideUp()

Tags:

How can I wait till the end of the jQuery function slideUp() before continuing the script?

<script type="text/javascript"> $(document).ready(function() {     $("div[class=item]").click(function() {         var id = $(this).attr("id");         $("#content").slideUp();         switch(id) {             // Applications             case "rampro":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/rampro.html");                 $("#content").slideDown();                 break             case "diskman":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/diskman.html");                 break             case "iconmap":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/iconmap.html");                 break             // Websites             case "benoks":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/benoks.html");                 break             case "linkbase":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/linkbase.html");                 break             case "jamesbrooks":                 $("#content").css("text-align", "left");                 $("#content").load("inc/pages/jamesbrooks.html");                 break             default:                 $("#content").css("text-align","center");                 $("#content").html("<h1>something went wrong, try again!</h1>");         }         return false;     }); }); 

like image 392
James Brooks Avatar asked Jul 05 '09 16:07

James Brooks


2 Answers

Use the callback mechanism and have your code run in the callback.

$('#something').slideUp('fast', function() {    ... stuff to do after the slide is complete... }); 
like image 51
tvanfosson Avatar answered Oct 16 '22 20:10

tvanfosson


slideUp() takes two arguments. If you pass a function as the second argument, it'll be called when the animation is complete.

http://docs.jquery.com/Effects/slideUp

like image 22
Turnor Avatar answered Oct 16 '22 19:10

Turnor