页面加载期间 IE 中没有图像的高度和宽度
No height and width of images in IE during page load
jQuery(window).load(function() {
jQuery.each(jQuery(".extraimgs"), function() {
//this.height = 0 and this.width=0 in IE only
if (this.height > this.width) {
if (this.height > 263) {
this.height = 263;
}
if (this.width > 354) {
this.width = 354;
}
}
else {
this.height = 263;
this.width = 354;
}
});
});
网页代码
<asp:DataList runat="server" ID="dlImages" RepeatColumns="2" RepeatDirection="Horizontal" RepeatLayout="Table" OnItemDataBound="dlImages_ItemDataBound" Style="display: none;">
<ItemTemplate>
<div>
<asp:Image runat="server" ID="imgPics" class="extraimgs" />
</div>
</ItemTemplate>
</asp:DataList>
我在IE中的这段代码有问题。在这里,我在运行时(页面加载事件 - 使用 jQuery)期间设置图像的高度和宽度,并使用代码隐藏设置图像源。
此代码在除 IE8 以外的所有浏览器中都运行良好。在页面加载事件中,我获取图像的高度和宽度,但我在IE8中没有获得图像的高度和宽度。在加载事件期间,我尝试了很多方法来获取图像的高度和宽度,但它不起作用。
有谁知道解决方案?
好的,根据我上面的评论,这是一个应该可以工作的版本:
jQuery(function() {
jQuery(".extraimgs").load(function() {
var $this = $(this);
if ($this.height > $this.width) {
if ($this.height > 263) {
$this.height = 263;
}
if ($this.width > 354) {
$this.width = 354;
}
}
else {
$this.height = 263;
$this.width = 354;
}
});
});
试试这个:
jQuery(document.body).load(function () {
jQuery(".extraimgs").each(function (i) {
if (this.height > this.width) {
if (this.height > 263) {
this.height = 263;
}
if (this.width > 354) {
this.width = 354;
}
}
else {
this.height = 263;
this.width = 354;
}
});
});
那么
$(document).load()
或$(document).ready()
而不是$(window).load()
呢?
相关文章:
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 根据图像高度添加类
- 尝试使用window.innerHeight和Javascript设置图像高度
- 图像高度只会从一大组图像中检索一次
- 为什么我的图像高度没有改变
- 使图像高度相同并定义共享的总宽度
- 在提交表单之前获取上传图像的图像高度和宽度
- Javascript:在 for 循环中编辑图像高度
- 如何使用 JQuery 获取真实的图像高度
- 根据原始图像高度使用 Photoshop 和 JavaScript 调整条件图像大小
- 基于移动方向的图像高度
- 我如何使用 Jquery 获取图像高度并将其除以 2
- 图像高度与图像宽度成比例,但图像宽度以父项的百分比为单位
- 使用 jQuery 调整图像高度
- 获取图像高度并将图像容器高度更改为自动
- 图像高度始终返回为0
- 获取不在内容中的图像高度
- 调整主图像高度的Nivo滑块
- 如何使用变量更改图像高度
- 获取图像高度属性并将其显示在CSS转换中