获得“真实”图像IE 中的宽度和高度
我目前正在构建一个网站并使用 Shadowbox JS 插件来显示图像。
因为我们通过 JSP 提供图像(而不是直接链接到图像文件),所以 Shadowbox 似乎无法动态确定它们的宽度和高度,因此只能在屏幕大小的覆盖层中打开图像。
可以使用“rel”手动将宽度和高度传递给 Shadowbox 插件,因此我使用以下代码解决了 FF/Chrome/Safari 的问题:
$('#pic1img').attr("src")).load(function() {
picWidth = this.width;
picHeight = this.height;
});
$(window).load(
function() {
var w = $("#pic1img").width();
var h = $("#pic1img").height();
if( picWidth < w ){ picWidth = w; }
if( picHeight < h ){ picHeight = h; }
$('#pic1').attr('rel', 'shadowbox[pics];height=' + picHeight + ';width=' + picWidth);
}
);
但我找不到任何方法可以在IE。
I'm currently building a site and using the Shadowbox JS plugin to display images.
Because we serve up images via a JSP (rather than linking directly to image files), Shadowbox seems unable to dynamically determine their width and height and so just opens the images in an overlay of ~the screen size.
It's possible to manually pass in widths and heights to the shadowbox plugin using 'rel', so I've got around the problem for FF/Chrome/Safari using the following code:
$('#pic1img').attr("src")).load(function() {
picWidth = this.width;
picHeight = this.height;
});
$(window).load(
function() {
var w = $("#pic1img").width();
var h = $("#pic1img").height();
if( picWidth < w ){ picWidth = w; }
if( picHeight < h ){ picHeight = h; }
$('#pic1').attr('rel', 'shadowbox[pics];height=' + picHeight + ';width=' + picWidth);
}
);
But I can't find any way to do the same in IE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦我开始以全尺寸加载缩略图,然后在加载后设置它们的宽度和高度,该代码实际上就起作用了。
问题是我将周围的 div 设置为
直到图像加载并且 IE 无法计算出隐藏图像的大小。
通过设置解决了这个问题
。
The code actually worked once I began loading the thumbnails at full size and then setting their width and height after load.
The issue was that I was setting a surrounding div to
until the images were loaded and IE can't work out the sizes of hidden images.
Resolved this by setting
instead.