Forums

  • # March 15, 2010 at 4:48 pm

    Hi,
    Is there a way to change the colour of a div as it moves across the screen in the horizontal plane?
    I would need it to change 5 times to different colours and not animate across the spectrum, just suddenly change.

    Any Help Appreciated.
    Thanks.

    # March 15, 2010 at 6:38 pm

    I don’t quite understand what you’re trying to do, but to change colors with javascript you can do one of several things.

    The first is do something like: document.getElementById(‘yourID’).style = ‘color:#XXXXXX’;

    or, you could use JQuery if you want a little more functionality. I’d recommend using JQuery only if you plan to use it a bunch, otherwise, it’s extra bandwidth for a simple color change.

    Build a function like this:

    Code:
    function changeColor(color, elementID) {
    document.getElementById(elementID).style = ‘color:’ + color;
    }

    then simply call the function with the color and id on any event you choose.

    # March 16, 2010 at 12:42 pm

    the code that Democritus supplied will change the color, as far as when it changes color, you still have to specify that.

    Without knowing more, like how the div moves, and when it should change color, we can’t really offer any more help.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag