通过jQuery加载的图像的高度和宽度 - 无法获得阿贾克斯 [英] Can't get ajax - loaded image's height and width via jquery
本文介绍了通过jQuery加载的图像的高度和宽度 - 无法获得阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我exteranlly通过AJAX加载图像像这样...
I'm loading an image exteranlly via ajax like so...
function load_image(image_href) {
var img = new Image();
$(img).load(function () {
$(this).hide(); $('#a_box').append(this);
$(this).fadeIn();
}, gallery_image_load_complete()
).error(function () {
}).attr('src', image_href);
}
function gallery_image_load_complete() {
conslole.log('complete')
$('#a_box img').height(); //wrong numbers, as though the image is partially loaded
$('#a_box img').width(); //wrong numbers
}
问题是我试图让加载的图像的高度和宽度的功能gallery_image_load_complete内()。 出于某种原因,该图像的高度和宽度都关闭,这是astohugh图像没有完全加载。
The problem is I'm trying to get the loaded image's height and width inside the function gallery_image_load_complete(). For some reason, this image height and width are off, it's astohugh the image hasn't fully loaded.
有人能帮助我吗?
推荐答案
gallery_image_load_complete()需要在加载事件处理函数中调用:
gallery_image_load_complete() needs to be called within the load event handler:
function load_image(image_href) {
var img = new Image();
$(img).load(function () {
$(this).hide(); $('#a_box').append(this);
$(this).fadeIn();
gallery_image_load_complete(); // now inside the load event handler
}).error(function () {
}).attr('src', image_href);
}
这篇关于通过jQuery加载的图像的高度和宽度 - 无法获得阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文