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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:25:44+00:00 2026-06-13T09:25:44+00:00

I am using the following script (which depends on jQuery UI) to animate the

  • 0

I am using the following script (which depends on jQuery UI) to animate the changing of the background colour of a DIV using the CSS below. You can see it in action on this page – it changes the colour in the doorway of the logo (you have to wait 10 secs to see a noticeable change). The transitions work fine apart from the change from the 5th colour back to the 1st which is a sudden change (i.e. no fade transition). I wonder if it would be possible to alter the script below to get this transition working too?

function changeColor(element, curNumber){
    curNumber++;

    if(curNumber > 5){
        curNumber = 1;
    }
    console.log(curNumber);
    element.addClass('color' + curNumber, 2000);
    // So previous classes get removed.
    element.attr('class', 'color' + curNumber);
    setTimeout(function(){changeColor(element, curNumber)}, 10000);  
}

changeColor($('#colourdoor'), 0);

CSS

.color1{
    background:#FDFBFB;
}

.color2{
    background: #BDF0F5;
}

.color3{
    background: #E5F5BD;
}

.color4{
    background: #D4D1F5;
}

.color5{
    background: #F5EAD0;
}​
  • 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-13T09:25:45+00:00Added an answer on June 13, 2026 at 9:25 am

    Here’s the code that works for me:

    function changeColor(element, curNumber){
        curNumber++;
    
        if(curNumber > 5) {
            // we are back at 1, animate removeClass instead
            curNumber = 1;
    
            // we don't need animation here since color5 is defined AFTER color1, (cascading)
            element.addClass('color' + curNumber);
    
            // we animate removeClass instead
            element.removeClass('color' + 5, 2000);
        } else {
            element.addClass('color' + curNumber, 2000);
            // So previous classes get removed.
            element.attr('class', 'color' + curNumber);
        }
        console.log(curNumber);
        setTimeout(function(){changeColor(element, curNumber)}, 10000);  
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script which does not work. it should be using jquery
I have the following script which will change the background image of a text
I am using the following script but it's giving syntax errors which I am
I have found the following script which is apparently written using the javascript framework
I can't figure out the problem in the following short script which should compare
Im using Jquery widget Autocomplete.My data source is a server-side script which returns JSON
I'm currently building a website using jquery. I've found a script which will cause
I have the following script which I am using in an intranet environment: function
I've tried to change filenames using following script: find dir/ -type f -exec mv
I'm using the following script in my website in order to create pagination next-previous

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.