Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-22-2011, 01:51 AM   PM User | #1
Mr.
Regular Coder

 
Join Date: Feb 2011
Posts: 112
Thanks: 8
Thanked 4 Times in 4 Posts
Mr. is an unknown quantity at this point
Question Help with Javascript on rollOver

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!
Mr. is offline   Reply With Quote
Old 09-22-2011, 03:29 AM   PM User | #2
Desmondowq
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Desmondowq is an unknown quantity at this point
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)";

}
Desmondowq is offline   Reply With Quote
Users who have thanked Desmondowq for this post:
Mr. (09-22-2011)
Old 09-22-2011, 03:41 AM   PM User | #3
Mr.
Regular Coder

 
Join Date: Feb 2011
Posts: 112
Thanks: 8
Thanked 4 Times in 4 Posts
Mr. is an unknown quantity at this point
awesome thank you!
Mr. is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:24 AM.


Advertisement
Log in to turn off these ads.