【发布时间】:2016-05-10 03:30:31
【问题描述】:
我有一个基于网格的布局页面,其中包含横向或纵向图像(固定宽度为380px)。每次图像是横向时,我都想根据其宽度将其大小增加到480px(因此所有图像的方形像素区域更加相等)。
我不确定如何正确调用图像。它应该应用于<body class="blog">页面上的所有imgs。
而且我不确定如何重新定义宽度(通常由 CSS 定义)以及如何确保 w/h 比率保持不变。
这是目前的代码
var ArchiveImage = $(".blog img");
if (ArchiveImage.width() > ArchiveImage.height()){
//landscape
ArchiveImage.width() = 480;
} else if (ArchiveImage.width() < ArchiveImage.height()){
//portrait
} else {
//square.
}
【问题讨论】:
-
首先,您可能需要遍历所有
img。即$(".blog img").each(function(i, item){ //resize code });
标签: jquery css image layout width