在 colorbox 插件中加载后如何获取实际图像宽度和高度?
我在 colorbox 中打开 MVC 视图。该视图加载一个图像,我让用户在其上添加注释。在我的注释插件工作并渲染画布之前,我需要 知道加载图像的宽度和高度。这设置了画布尺寸。
我能够在 FF、Chrome、Opera 中很好地获取图像的宽度和高度。 但在 IE8 中,我总是将图像宽度和高度设为 0
有没有人可以帮助我一次获取图像尺寸 图像已加载?
这是我如何调用 colorbox 打开我的 MVC 视图:
<a href="site/photos/album/1234" class="notes colorbox"></a>
这是视图:
<div id="dvImg">
<img id="imgAnnotate" src="path/abc.jpg" />
</div>
$(function () {
$("#imgAnnotate").load(function () {
Width = this.width;
Height = this.height;
alert('W=' + Width + ' H=' + Height); <-- IE shows as W=0 H=0
});
});
我还尝试了 imagesLoaded 插件,但在 colorbox 上不起作用:
$(function () {
var $dvImg = $('#dvImg');
function loopImages($images) {
$images.each(function () {
alert('h6=' + $(this).height() + ' w6=' + $(this).width()); //FF says 0
alert('h7=' + this.height + ' w7=' + this.width); //FF OK!!! not IE
});
}
$dvImg.imagesLoaded(function ($images) {
loopImages($images);
});
});
另一点: $(window).load()
in视图根本不发射。可能是因为它 已加载到彩盒中?
不管怎样,这看起来非常非常难做到!
I open a MVC view in colorbox. That view loads an image on which I let user add annotations. Before my annotation plugin works and render the canvas, I need to
know the width and height of the image loaded. This sets the canvas dimension.
I am able to get the image width and height just fine in FF, Chrome, Opera.
But in IE8, I always get image width and height as 0
Is there anyone who can help me with getting the image dimension once
the image is loaded?
Here is how I call colorbox to open my MVC view:
<a href="site/photos/album/1234" class="notes colorbox"></a>
This is the view:
<div id="dvImg">
<img id="imgAnnotate" src="path/abc.jpg" />
</div>
$(function () {
$("#imgAnnotate").load(function () {
Width = this.width;
Height = this.height;
alert('W=' + Width + ' H=' + Height); <-- IE shows as W=0 H=0
});
});
I also tried a imagesLoaded plugin but doesn't work on colorbox:
$(function () {
var $dvImg = $('#dvImg');
function loopImages($images) {
$images.each(function () {
alert('h6=' + $(this).height() + ' w6=' + $(this).width()); //FF says 0
alert('h7=' + this.height + ' w7=' + this.width); //FF OK!!! not IE
});
}
$dvImg.imagesLoaded(function ($images) {
loopImages($images);
});
});
Another point: $(window).load()
in the view is not firing at all. May be because it
is loaded in colorbox?
Anyway, this seems very very tough to do!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
try this