[英]How can I make an image enlarge on a javascript event when its size is set through css?
I have some CSS (Below) defining an images size 我有一些CSS (下面)定义图像大小
#latestImages img
{
height: 95px;
width: auto;
}
This is affecting these images: 这会影响这些图像:
<img src="@images.ImagePath" alt="@images.NameOfImage" />
When i set an onmouseover event to this image like so: 当我将onmouseover事件设置为此图像时,如下所示:
<img src="@images.ImagePath" alt="@images.NameOfImage" onmouseover="this.width=100;this.height=100;" onmouseout="this.width=200;this.height=200;"/>
The images height and width do change in the html when the source is viewed but there is no visible change, but when i removed the css the changes did occur. 当查看源时,图像的高度和宽度确实在html中发生变化,但是没有可见的变化,但是当我删除了css时,确实发生了变化。 Does anyone know why this is?
有人知道为什么是这样吗? And is there anything I can do different to keep the css as is and have javascript enlarging the image?
还有什么我可以做的不同保持css原样并让javascript放大图像? Thanks in advance!
提前致谢!
You can use this format in your onmouseover handler: this.style.width="50px"
. 您可以在onmouseover处理程序中使用此格式:
this.style.width="50px"
。 Or better yet, don't put your JS in your HTML, and write a function for what you are trying to do. 或者更好的是,不要将你的JS放在你的HTML中,并为你想要做的事情编写一个函数。
onmouseover="this.style.width='100px';this.style.height='100px';"
onmouseout="this.style.width='200px';this.style.height='200px';"
Styles need units. 样式需要单位。 In this case
px
. 在这种情况下
px
。 Otherwise it could be pt
, in
, or em
. 否则它可能是
pt
, in
或em
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.