![](/img/trans.png)
[英]Why does an image display at greater that its actual size when pasting into Excel, and how can I get it to display at its natural size?
[英]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
。 否則它可能是pt
, in
或em
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.