我正在尝试获取图像的实际宽度...这是有问题的图像
<img src="upload/<?php echo $array['image'] ?>" height="200" class="active" />
这是我在 jQuery 中尝试过的
$(window).bind('load', function() {
var img_width = $("#slideshow").find("img").width();
$("#slideshow img").css("width", img_width);
alert(img_width);
});
对于我尝试过的每张图片,警报都会返回 255,这是 div 幻灯片的宽度。由于这些图像的高度均为 200,它们将具有不同的宽度,我的问题是,如何获得这些宽度?
谢谢, J
最佳答案
这应该用所有图像的宽度填充一个数组:
$(window).bind('load', function() {
var img_widths = [];
var imgs = $("#slideshow").find("img");
imgs.each(function() {
img_widths.push($(this).width());
});
});
关于jQuery - 获取图像的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017029/