Results 1 to 7 of 7

Thread: jquery actions happen at once, not in a series

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default jquery actions happen at once, not in a series

    how can i make the actions happen all together at the same time, not in a series
    for instance this code will show the balloon first which takes 100th of a second then go to the next list
    i want this list to happen at once

    Code:
    $("li.il2, li.sw2").click(function () {
    	  $("#balloon").show(100);
    	  $("li.il2").animate({backgroundPosition: '0 -17px'})
      });
    Last edited by ggalan; 11-18-2010 at 04:06 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I think the best you can do is try running the animation without putting it in the queue:

    Code:
    $("li.il2, li.sw2").click(function () {
    	  $("#balloon").show(100);
    	  $("li.il2").animate({backgroundPosition: '0 -17px'}, {queue: false})
      });
    For (a little) more info see .animate( properties, options ) on the jQuery API manual page for animation:

    http://api.jquery.com/animate/
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    queue, thank will look into it
    but how do you get rid of queue in something like this?

    Code:
    $("#balloon").show(100);

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    By my reading of the manual, in the code as you have it, that begins the queue. If all subsequent animation type commands use the .animate() with queue: false, then you need not bother with removing the .show(100) from the queue. None of the subsequent animations will respect its queue.

    Alternatively, you could break .show(100) into its component parts and make it a .css().animate() with queue: false.

    Or, if it works like I think it says it will, do:

    Code:
    $("#balloon").dequeue().show(100);
    see:

    http://api.jquery.com/dequeue/

    Be careful though when taking things out of queue. Too many animations at once will cause problems on some systems. Sometimes it's not the fact that a queue exists that is messing up your intended effect, rather the order in which your choosing to do the effects in.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i see, .dequeue() didnt do it for me on this but will keep this in mind

    thanks again!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, as I said, if the show(100) comes first, it shouldn't matter if it goes into the queue or not. There should be no queue yet.

    With jQuery though it's helpful to play around. The order in which things are done often plays a role. The dequeue() function may only effect the queue for the selected element(s). If so, you may have to include the other elements that you will be animating later and exclude them for the .show() - something like:

    Code:
    $("li.il2").animate({backgroundPosition: '0 -17px'}, {queue: false});
    $("li.il2, #balloon").dequeue().filter("#balloon").show(100);
    Or:

    Code:
    $("li.il2, #balloon").dequeue().filter("#balloon").show(100);
    $("li.il2").animate({backgroundPosition: '0 -17px'}, {queue: false});
    Or various other possibilities, here's one:

    Code:
    $("li.il2").animate({backgroundPosition: '0 -17px'}, {queue: false});
    $("li.il2").dequeue();
    $("#balloon").show(100);

    Also, from the dequeue man page's comments section:

    Quote Originally Posted by Thamus
    . . . The information to be gained by reading this vague piece of documentation confines itself to the mere fact that there is a method called .dequeue(), which can be used to alter the effect chaining behavour.
    I had to take a look at the jQuery source to understand what it is actually good for.
    Perhaps you should. When I have more time I probably will.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    nice, thanks as lot!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •