简体   繁体   English

使用JavaScript通过鼠标悬停放大图像

[英]Enlarge image through mouseover using JavaScript

As part of an assignment I have to enlargen an image using JavaScript through a mouseover. 作为作业的一部分,我必须通过鼠标悬停使用JavaScript来放大图像。 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. 此标记的任何父项都应具有固定的px宽度/高度值。

Can you check if you have set the width/height for the parent anywhere on the page. 您可以检查是否在页面上的任何地方设置了父级的宽度/高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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