javascript - Random Hover Effects -
how can randomize hover effects?
for example:
<p>test</p> p:hover { background: yellow; } p:hover: background: red; }
please note above for-example only. question is, how can randomize hover effects, shows background:yellow;
, background:red;
once in random order on onmouseover
?
there should not order, example: on first hover - 1 class added, on second - another. should completely random.
use following function random colors , use mouseover event change background color.
function getrandomcolor () { var letters = '0123456789abcdef'.split(''); var color = '#'; (var = 0; < 6; i++) { color += letters[math.floor(math.random() * 16)]; } return color; } }) $( "p" ).mouseover(function() { $(this).css("background",getrandomcolor()); });
please check fiddle
.
Comments
Post a Comment