简体   繁体   中英

Enlarge image through mouseover using JavaScript

As part of an assignment I have to enlargen an image using JavaScript through a mouseover. When the image is enlarged it shouldn't move any of the other elements on the page however. When the mouse is moved from the image, it should restore back to the original size.

This is the code that I have so far but it just seems to do absolutely nothing.

function imageEnlarge() {

 document.getElementById('1').style.height=100%;
 document.getElementById('1').style.width=100%;
 document.getElementById('1').style.position='absolute';
 }

function imageReset()   { 

 document.getElementById('1').style.height=80%;
 document.getElementById('1').style.width=80%;
 document.getElementById('1').style.position='absolute';
}

<img src="home2.jpg" class="homeimage" alt="View of a beach"
                 id="1" onmouseover="imageEnlarge();" onmouseout="imageReset();"

Any ideas on where I am going wrong. The feedback from my teachers hasn't been the best so I am at a complete loss where to go on this.

Please check this code

 function imageEnlarge() { document.getElementById('1').style.height="100%"; document.getElementById('1').style.width="100%"; document.getElementById('1').style.position='absolute'; } function imageReset() { document.getElementById('1').style.height="80%"; document.getElementById('1').style.width="80%"; document.getElementById('1').style.position='absolute'; } 

Any of the parent for this tag should be having fixed px values for width/height.

Can you check if you have set the width/height for the parent anywhere on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM