1
我必须知道我的动态图像的尺寸并在图像上设置真值。所以我尝试了一个函数,像这样:想知道图像的原始大小,并通过属性在jQuery中指定
$().ready(function() {
imageSize();
});
// Assign width/height to img
function imageSize() {
// Specify image dimensions
$('img').each(function() {
var findImgWidth = $(this).width();
var findImgHeight = $(this).height();
$(this).attr('width', findImgWidth);
$(this).attr('height', findImgHeight);
});
}
那么,它适用于指定但不计算维度。每张图片的尺寸为0px
我该如何解决?
改为使用窗口onload事件,您必须等待图像加载才能获取其尺寸。 – Shikkediel
@Shikkediel是的!这是它,谢谢! –