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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:21:27+00:00 2026-06-01T12:21:27+00:00

Hi I am trying to get this script to show random colours one after

  • 0

Hi I am trying to get this script to show random colours one after the other when the li scrolls up but so far I have it doing this but it is not smooth it changes when it restarts so you dont get smooth effect and it changes colour twice any help will be great thanks.

 $("#carousel ul").animate({marginTop:-100},2000,function(){

    function pad(s,i,c,r){
    i=i+1-s.length;
    if(i<1)return s;
    c=new Array(i).join(c||" ");
    return r?s+c:c+s;
    };

    hue  = "#"+pad((Math.random()*0x1000000<<0).toString(16),6,"0");
    hue2 = "#"+pad((Math.random()*0x1000000<<0).toString(16),6,"0");
    hue3 = "#"+pad((Math.random()*0x1000000<<0).toString(16),6,"0");

    $(this).find("li:last").after($(this).find("li:first"));
    $('#div1').css({backgroundColor: hue});
    $('#div2').css({backgroundColor: hue2}); 
    $('#div3').css({backgroundColor: hue3});

    $(this).css({marginTop:0});
    })  
    },1000);  
});

my example can be found here http://swipedstudio.com/jtoy/
Thanks in advance!

  • 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-01T12:21:29+00:00Added an answer on June 1, 2026 at 12:21 pm

    Working code:

    var t = setInterval(function(){ 
    
     $("#carousel ul").animate({marginTop:-100},2000,function(){
    
        function pad(s,i,c,r){
        i=i+1-s.length;
        if(i<1)return s;
        c=new Array(i).join(c||" ");
        return r?s+c:c+s;
        };
    
        hue  = "#"+pad((Math.random()*0x1000000<<0).toString(16),6,"0");
    
        $(this).find("li:last div").css({backgroundColor: hue});
        $(this).find("li:last").after($(this).find("li:first"));
    
        $(this).css({marginTop:0});
        })  
        },1000); 
    

    The issues:

    • You were changing the color of every div on every interval when really you only wanted to change the last one in the list
    • When you change the color of the last div, you need to select it using $(li:last div) because the three divs cycle through the list. When you select div1, div2, or div3 specifically, it could be at any place in the list
    • The color change (at least with the $(li:last div) selector) needed to take place prior to the after() statement. Your original code changes the order of the divs and then changes the color
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to register this simple script, but i can't get this to show
I'm trying to get this piece of script to work, but it keeps dying
I am currently trying to get OpenLayers to show a WMS-Layer. Doing this I
I am trying to get this script to work. it opens up a directry
I get this error when trying ruby script/console Rails requires RubyGems >= . Please
Im trying to get this working but for some reason it's just not right.
I am trying to get show hide to work on multiple objects but I
I have this jQuery code: <script type=text/javascript> $(function() { $(.one-edition img).hover(function() { $(this).next(.editions-info-text).show(); },
I am trying to get this simple script to work. Basically, when a user
So I've been trying to get this script working in IE 7 & 8.

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.