Search code examples
htmlmouseovermouseout

HTML MouseOver and MouseOut Error


<tr>
<td> <span id="dummy" onclick="playSound(this,'vowels/ear.mp3');">
<img src="pics/ie.jpg" onmouseover="this.src='pics/dipthongs/ear.jpg';this.width=200;this.height=250" onmouseout="this.src='pics/ie.jpg';this.width=100;this.height=150"/>
</span> </td>

My problem is that the images get so big when i load the page. I have to hover to all the images before it returns to the size i declare for them. thanks!


Solution

  • Add a class to the image to fix the width and height parameters.

    <img src="/image.png" class="image1" />
    

    Now CSS using min-width/height and max-width/height:

    .image1 {
    max-width: 500px;
    max-height:500px;
    min-width: 120px;
    min-height: 120px;
     }
    

    Create Functions

    function mouseEffect(ele,image,className){
     ele.src=image;
     ele.className= className;
     }
    

    Example:

    http://jsfiddle.net/mwtjt/