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 4624036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:04:24+00:00 2026-05-22T03:04:24+00:00

Fiddle here: http://jsfiddle.net/F6nJu/ I have a colored box: <div id=colorblock></div> #colorblock { background:#3ff; width:

  • 0

Fiddle here:
http://jsfiddle.net/F6nJu/

I have a colored box:

<div id="colorblock"></div>
#colorblock { background:#3ff; width: 100%; height: 300px; }

I have an array of colors created in javascript:

var arr = [ "#f00", "#ff0", "#f0f", "#f66"];

I iterate through those colors with a jQuery each() function:

$.each(arr, function(key, value) {
  $('#colorblock').delay('1200').animate({backgroundColor:value}, 600);
});

When the array iterates to the end, how can I start the array iteration over (so the animation goes on forever)?

  • 1 1 Answer
  • 1 View
  • 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-05-22T03:04:24+00:00Added an answer on May 22, 2026 at 3:04 am
    var arr = ["#f00", "#ff0", "#f0f", "#f66"];
    
    // run through the array forever
    (function recurse(counter) {
        // get the colour
        var color = arr[counter];
        // animate it
        $('#colorblock').delay('1200').animate({
            backgroundColor: color
        }, 600);
        // delete the value to save memory
        delete arr[counter];
        // add the value at the end of the array
        arr.push(color);
        // run it again for the next number
        setTimeout(function() {
            recurse(counter + 1);
        }, 200);
    // start it for the first number.
    })(0);
    

    Infinite recursion. Delete the current entry, then add the current value to the end.

    Live Example

    For those who are interested in what the array looks like:

    ["#foo", "#ff0", "#f0f", "#f66"] (counter = 0)
    [undefined, "#ff0", "#f0f", "#f66", "#foo"] (counter = 1)
    [undefined, undefined, "#f0f", "#f66", "#foo", "#ff0"] (counter = 2)
    [undefined, undefined, undefined, "#f66", "#foo", "#ff0", "#f0f"] (counter = 3)
    [undefined, undefined, undefined, undefined, "#foo", "#ff0", "#f0f", "#f66"] (counter = 4)
    etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fiddle here: http://jsfiddle.net/maniator/SZpkF/1/ The green box is supposed to move with
I have a fiddle here - http://jsfiddle.net/hhimanshu/SDr3F/2/ The left pane is already available I
I have a fiddle here http://jsfiddle.net/WULsZ/1/ I load jQuery first and the code is
Fiddle is here - http://jsfiddle.net/ashwyn/a45ha/ HTML here - <div class=parent> <div class=a>Class A</div> <div
Here is my fiddle: http://jsfiddle.net/jamesbrighton/wxWgG/4/ HTML: <div> <p class=click>Click 1</p> <p>This should be ignored</p>
Fiddle here: http://jsfiddle.net/cgweb87/r3NEX/ When you click on the h2, it slides the div up
I have this fiddle here: http://jsfiddle.net/CS5Bb/2/ Alls I want to happen is when I
I have a fiddle here: http://jsfiddle.net/justinboyd101/4nrbb/ Here is my question: Why are my console.log
I have created fiddle here: http://jsfiddle.net/ozzy/WEGMh/ How it should look is here: Issue is
I have this fiddle here: http://jsfiddle.net/maniator/MUa7P/ In this example a user picks a certain

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.