Team:StanfordBrownSpelman/jquery.color hover

From 2014.igem.org

Revision as of 22:57, 11 August 2014 by Jotthek (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

$(document).ready(function() { $( function() {

   $("a, #title").hover(function() {
           /* Store jQuerized element for multiple use */
           var $this = $( this );
           var randomColor = getRandomColor();
           $this
               /* Set the pre-color data */
               .data( 'prehovercolor', $this.css( 'color' ) )
               /* Set the new color */
               .css( 'color', randomColor);
       },
       function() {
           /* Store jQuerized element for multiple use */
           var $this = $( this );
           $this
               /* Set the color back to what is found in the pre-color data */
               .css( 'color', $this.data( 'prehovercolor') );
       });
       });
       });


function getRandomColor() {

   //Store available css classes
   var colors = new Array("#00ffff", "#33cccc", "#00ffcc", "#33ffcc", "#00cc99", "#33cc99", "#00ff99", "#00cc66", "#33cc66", "#33ff99");
   //Give a random number from 0 to 10
   var randomColor = Math.floor(Math.random()*11);
   return colors[randomColor];

}