Search code examples
csscolorsdom-manipulation

How to change word color?


I want to make it such that when the text in the dom starts loading, text is red. At random, each letter starts animating a fade/change to blue on first load. Is this possible in CSS3 only or does javascript have to be involved?


Solution

  • while i think it could be done with CSS i would through the easier way to do it using jQuery: you need this plugin and then:

    $(document).ready(functiom() { //this could be any event
        $('#your_div_id').animate({color: 'blue'});
    });
    

    your question isn't clear, if you want to get random colors then make an array of colors and randomly select a color, this is what i used for my site:

    var colors = new Array("blue", "green", "#ffffff", "color4", "color5");
    var rand = Math.floor(Math.random()*5);
    

    and in you replace 'blue' from the pref function with colors[rand]

    next time, keep your question a little more general so others can use it as well