PDA

View Full Version : Quick Javascript question for a newbie :)



VJ
20-06-11, 23:28
okay, i'm using jQuery but i don't think that makes a difference?
basically, I've got this code


$("input").click(function() {
$("#answerform").slideUp("fast").delay(400);
$("#log").html( "answering: " + $(":checked").val() );
$("#" + $(":checked").val()).after($("#answerform"));
$("#answerform").slideDown("slow");
});


Currently, it appears to do everything at the same time...
Is there a way I can get it run as a script? like each line after another?

onehandharry
21-06-11, 03:20
It will do everything at the same time because thats what its being told to do, you will need to to use a while loop, if statements, etc

cleggypdc
21-06-11, 09:41
Javascript is single threaded and therefore will NOT wait for an animation to finish before going to the next, many animations use callback functions to queue. e.g.


$('#some-id').fadeOut('slow', function() {
$('#some-id').fadeIn('slow');
});

you can specify your animations in order by using callbacks, or you can use jQuery queues

http://api.jquery.com/queue/