hover over image

Discussion in 'HTML & Website Design' started by bobocheez, Jul 24, 2009.

  1. #1
    Hi,
    How do you get a picture to move when hovering your mouse over it?(with html)

    I have this but it has to reload the image every time

     
    <img
    border="0"
    src="img/image1.jpg"
    onmouseover="this.src='img/image2.jpg';" onmouseout="this.src='img/image1.jpg';"
    />
    
    HTML:
    Image1 & 2 would be combined into one so when someone hovers over it, the image would just move and reveal the other image.

    Thanks
     
    bobocheez, Jul 24, 2009 IP
  2. forumhelper

    forumhelper Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The following will hide an image when you hover over it and show it when you move the mouse away:

    
    <img src="img/image1.jpg" border="0" id="image1" onmouseover="document.getElementById('image1').style.display='none';" onmouseout="document.getElementById('image1').style.display='inline';" />
    
    Code (markup):
     
    forumhelper, Jul 25, 2009 IP
  3. forumhelper

    forumhelper Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If the above hasn't helped you, please let me know. You will probably need to use some CSS to get one image to hide behind another, so let me know if you need help with that.
     
    forumhelper, Jul 25, 2009 IP
  4. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    That's not what I'm looking for.
    I saw one time a simple code in html with no css one time but don't remember when and how.

    ...I'm not sure if it had the onmouseover thing but you had to specify what when you hovered over it it would move in a certain direction x number of pixels
     
    bobocheez, Jul 25, 2009 IP
  5. forumhelper

    forumhelper Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You could use the following code to move an image x and/or y pixels on hover over:

    
    <script type="text/javascript">
    function move_image(image,x,y) {
    	image = document.getElementById(image);
    	image.style.position = "relative";
    	image.style.top = x+"px";
    	image.style.left = y+"px";
    }
    </script>
    <img src="image.jpg" id="image1" onmouseover="move_image('image1',100,100)" />
    
    Code (markup):
     
    forumhelper, Jul 25, 2009 IP
  6. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #6
    bobocheez, Jul 25, 2009 IP
  7. forumhelper

    forumhelper Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ah, I see. You're welcome for the help, I'm glad you found what you were looking for.
     
    forumhelper, Jul 26, 2009 IP