Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:37:33+00:00 2026-06-10T18:37:33+00:00

I am trying to learn how to use the .queue() JQuery method. So I

  • 0

I am trying to learn how to use the .queue() JQuery method. So I started with a basic animation using only setTimeout. I have the code here:

http://jsfiddle.net/2gJQS/8/

I am wondering how to achieve this same animation using queues. The reason for this is I want to be able to add a ‘cancel’ button to the page that would completely cancel all future steps. Right now if you press the Start button several times quickly, the setTimeout’s pile on each other and make it look strange.

I tried listing each animation separately in something like:

$('#target').queue(function(){
    $(this).delay(1000).fadeIn(1000);
    $(this).dequeue();
});

But only the fadeIns and fadeOuts happened at the right time, and not the color and text changes. So I added setTimeout’s inside the queue functions for the color and text changes, and this made the timing work. But then when I called

$('#target').clearQueue();

it only stopped the fadeIns and fadeOuts, while the color and text changes still happened.

To summarize my question:

  1. How can I achieve the animation in the link while also having a cancel button that will completely clear all future steps if pressed?

  2. If the answer to 1 is to use queue(), then how do I do this correctly (in light of my failed attempts described above)?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:37:35+00:00Added an answer on June 10, 2026 at 6:37 pm

    Functions like .html() and .css() don’t use the animation queue, so you should use .queue() to schedule those calls in between other animations, and then use .stop(true, true) to cancel the queue if the start button is pressed again.

    Absolutely do not mix setTimeout with jQuery animations – it won’t work reliably.

    See http://jsfiddle.net/alnitak/EKNAd/ for your fiddle corrected to use jQuery animation queues:

    $('#target').stop(true, true)
        .html("This is one.")
        .css('color', '#000000')
      .fadeIn(1000).fadeOut(2000).queue(function() {
        $(this).html("This is two.").css('color', '#dc0000');
        $(this).dequeue();
    }).fadeIn(1000).fadeOut(2000).queue(function() {
        $(this).html("This is three").css('color', '#990099');
        $(this).dequeue();
    }).fadeIn(1000).fadeOut(2000);
    

    Also, I previously posted this function to allow calling any jQuery function as if it were queued:

    (function($) {
        $.fn.queued = function() {
            var self = this;
            var func = arguments[0];
            var args = [].slice.call(arguments, 1);
            return this.queue(function() {
                $.fn[func].apply(self, args).dequeue();
            });
        }
    }(jQuery));
    

    See http://jsfiddle.net/alnitak/AYMY7/ for your function rewritten to use this:

    $('#target')
        .stop(true, true)
        .html('This is one')
        .css('color', '#000000')
        .fadeIn(1000)
        .fadeOut(2000)
        .queued('html', 'This is two')
        .queued('css', 'color', '#dc0000')
        .fadeIn(1000)
        .fadeOut(2000)
        .queued('html', 'This is three')
        .queued('css', 'color', '#990099')
        .fadeIn(1000)
        .fadeOut(2000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn and use html5 and have a basic layout but
I'm trying to learn how to use jQuery templates using this old ScottGu's blog
I'm trying to learn how to use the force.layout features in D3.js and have
I am trying to learn how to use Cascadding Style Sheets. I have a
I have been trying to learn to use github, it has been fine until
I'm trying to learn to use ANTLR, and seem to have come across an
im trying to learn how to use javascript objects, and got some issue here.
I'm trying to learn to use only the keyboard with some applications, one of
I'm trying to learn how to use OpenMP by parallelizing a monte carlo code
I'm trying to learn to use xml in Java (Android platform, using Eclipse and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.