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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:39:32+00:00 2026-05-24T09:39:32+00:00

I was hoping someone could show me efficient JQuery to animate between 4 background

  • 0

I was hoping someone could show me efficient JQuery to animate between 4 background colors in a div class.

I would like these events to be triggered by time, not click or hover. I’ve seen posts on hover and toggle, but as someone not very proficient in JQuery, I didn’t feel comfortable copying and pasting parts here and there.

Thank you

  • 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-05-24T09:39:33+00:00Added an answer on May 24, 2026 at 9:39 am

    I dont know if you mean animated as in fading to the next, but heres a simple quick example of changing the color every 2 seconds. First example does not require jQuery.

    Live Demo

    function changeColor(curNumber){
        curNumber++;
    
        if(curNumber > 4){
            curNumber = 1;
        }
        document.body.setAttribute('class', 'color' + curNumber);
        setTimeout(function(){changeColor(curNumber)}, 2000);  
    }
    
    changeColor(0);
    

    Update animating color

    Second example requires Jquery UI if you wish to fade between classes or background colors.

    Demo 2

    function changeColor(element, curNumber){
        curNumber++;
    
        if(curNumber > 4){
            curNumber = 1;
        }
    
        element.addClass('color' + curNumber, 1000);
    
        // So previous classes get removed.
        element.attr('class', 'color' + curNumber);
    
        setTimeout(function(){changeColor(element, curNumber)}, 2000);  
    }
    
    changeColor($('#testElement'), 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping someone could show how to properly append an array created with
Just like the title says. I was hoping someone could direct me to documents/resources
I was hoping someone could help me with this I have data like this
I was hoping someone could validate my assumptions before I recommend that my client
I was hoping someone could explain to me how eclipse automatically deploys to your
I was hoping someone could answer my quick question as I am going nuts!
I was hoping someone could give me a hand on how I write this
I was hoping someone could explain why my application when loaded uses varying amounts
I am having a problem with LINQ and I was hoping someone could explain
I'm not seeing the error and was hoping someone could figure it out: public

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.