繁体   English   中英

当javascript事件的大小通过css设置时,如何使图像放大?

[英]How can I make an image enlarge on a javascript event when its size is set through css?

我有一些CSS (下面)定义图像大小

#latestImages img 
{
    height: 95px;
    width: auto;
}  

这会影响这些图像:

<img src="@images.ImagePath" alt="@images.NameOfImage" />

当我将onmouseover事件设置为此图像时,如下所示:

<img src="@images.ImagePath" alt="@images.NameOfImage" onmouseover="this.width=100;this.height=100;" onmouseout="this.width=200;this.height=200;"/>

当查看源时,图像的高度和宽度确实在html中发生变化,但是没有可见的变化,但是当我删除了css时,确实发生了变化。 有人知道为什么是这样吗? 还有什么我可以做的不同保持css原样并让javascript放大图像? 提前致谢!

您可以在onmouseover处理程序中使用此格式: this.style.width="50px" 或者更好的是,不要将你的JS放在你的HTML中,并为你想要做的事情编写一个函数。

onmouseover="this.style.width='100px';this.style.height='100px';"
onmouseout="this.style.width='200px';this.style.height='200px';"

样式需要单位。 在这种情况下px 否则它可能是ptinem

暂无
暂无

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

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