...

View Full Version : Help with Javascript on rollOver



Mr.
09-22-2011, 01:51 AM
I have a div in my HTML that that when rolled over reveals an image.

I can't figure out how to place a random image from a set of 5 images to appear in the background of that div when it is rolled over again. Please help me!

Desmondowq
09-22-2011, 03:29 AM
There is more than one way of writing this. Hope it helps

HTML
<div id='picture' onmouseover="mouseover()"></div>

JS
function mouseover(){
var rand_Img = Math.floor(Math.random()*5+1);
var img_roll_over = document.getElementById('picture').style.backgroundImage="url(Image_"+rand_Img+".jpg)";

}

Mr.
09-22-2011, 03:41 AM
awesome thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum