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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:28:52+00:00 2026-05-27T06:28:52+00:00

So far, I have a simple script that checks the size of the document

  • 0

So far, I have a simple script that checks the size of the document and creates a 1px div for each line in the doc and applies a random color to each line. I want to animate each lines background color individually, so all the lines pulsate and change colors.

Here is my code:

<script type="text/javascript">
    $(document).ready(function() {
        var pageHeight = $(window).height();
        for(var i = 0; i < pageHeight; i++) {
            $('body').prepend('<div class="myDiv '+i+'"></div>');
        };

        $('.myDiv').each(function() {
            var myColor = randomColor();
            //alert (myColor);
            $(this).css("background-color", "rgb(" + myColor + ")");
        });
    });

    function randomColor () {
        var color1 = randomFromTo(100,255);
        var color2 = randomFromTo(200,255);
        var color3 = randomFromTo(0,100);
        return color1 + "," + color2 + "," + color3;
    };

    function randomFromTo(from, to){
        return Math.floor(Math.random() * (to - from + 1) + from);
    }
</script>

<style>
    body { margin:0; }
    .myDiv { height:1px; }
</style>
  • 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-27T06:28:53+00:00Added an answer on May 27, 2026 at 6:28 am

    There is probably a more elegant way to do this, but this is what I came up with. Create a function for the animate. Then use the functions callback to cycle.

    http://jsfiddle.net/cYzmp/

    You will need to use jQuery UI because default jQuery does not support animation of background colors. I am using it in the fiddle.

    Also, this is incredibly cpu intensive. It has one of my two processors pegged at 50% all the time. I don’t think you can expect your users to have a very pleasant experience if this is going to be going on all the time.

    $('.myDiv').each(function() {
            var myColor = randomColor();
            $(this).css("background-color", "rgb(" + myColor + ")");
            animateBG(this);
        });    
    });
    
    function animateBG(element) {
        $(element).animate({ backgroundColor: "rgb(" + randomColor() + ")"}, 3000, function() {
            animateBG(this);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that grabs the 'id' of a clicked 'div' and uses
I have a simple image upload script that uses SimpleImage.php (http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/) to resize and
I have a simple reporting script that takes 5-10 minutes to run. It's triggered
I have a very simple script that uses Copy-Item in the Task Build section
So far I have managed to write some code that should print the source
I'm trying to wrap my head around MSBuild. I have a very simple script
I'm trying to write a simple Python script that inserts .odt documents into an
I have a script that links to the server I am hosting (IP can
I've got a simple perl subroutine that checks to see if google is still
I have a large filesystem that I need to traverse for errors. Each file

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.