Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Mr.
    Mr. is offline
    Regular Coder
    Join Date
    Feb 2011
    Posts
    112
    Thanks
    8
    Thanked 4 Times in 4 Posts

    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!

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post
    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)";

    }

  • Users who have thanked Desmondowq for this post:

    Mr. (09-22-2011)

  • #3
    Mr.
    Mr. is offline
    Regular Coder
    Join Date
    Feb 2011
    Posts
    112
    Thanks
    8
    Thanked 4 Times in 4 Posts
    awesome thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •