![](/img/trans.png)
[英]Resize image slider to the current image's aspect ratio in JavaScript
[英]JavaScript resize image to aspect ratio
我想將尺寸設為980:1000的圖像調整為1:1的寬高比,或者將尺寸為1500:900的圖像調整為16:9。 我怎樣才能做到這一點 ? 我只希望圖像變小,以免它們被拉長(980:1000到例如980:980)。
這是在瀏覽器中嗎? 最簡單的方法可能是使用background-size:cover。
http://css-tricks.com/perfect-full-page-background-image/
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
您可以通過將圖像放置在wrapper元素內,然后將大小設置為wrapper並將其溢出屬性隱藏起來,以使圖像看起來被裁剪而不會拉伸。
<div style="overflow:hidden; height:980px; width: 980px;" > <img src="img_1000x980.jpg" /> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.