Can';t获取ajax加载的图像';通过jquery设置高度和宽度
我正在通过ajax外部加载一个图像,就像这样Can';t获取ajax加载的图像';通过jquery设置高度和宽度,jquery,ajax,image,dom,width,Jquery,Ajax,Image,Dom,Width,我正在通过ajax外部加载一个图像,就像这样 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(fun
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
}
问题是我试图在函数库\u image\u load\u complete()中获取加载图像的高度和宽度。
由于某些原因,此图像的高度和宽度已关闭,这是因为图像尚未完全加载
有人能帮我吗?你知道高度和宽度属性告诉你DOM中图像对象的大小,而不是底层图像文件本身,对吗?你知道高度和宽度属性告诉你DOM中图像对象的大小,而不是底层图像文件本身,是吗?我现在手头没有代码,但是当我需要一个任意图像的大小来决定如何显示它时,我会预加载一个隐藏元素,并获得@loaded元素的大小。然后做你想做的,把图像放在需要的地方
工作正常。我现在手头没有代码,但是当我需要任意图像的大小来决定如何显示它时,我会预加载一个隐藏元素,并获得@loaded元素的大小。然后做你想做的,把图像放在需要的地方
工作正常。需要在加载事件处理程序中调用gallery\u image\u load\u complete()
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);
}
需要在加载事件处理程序中调用gallery_image_load_complete():
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);
}
但我没有调整图像大小,没有css、脚本或任何限制。它在dom中的高度应该是它的实际高度。但是我没有调整图像大小,没有css、脚本或任何限制。它在dom中的高度应该是它的实际高度。load方法的第一个参数应该是URL,它似乎丢失了。可以解释问题。load方法的第一个参数应该是URL,它似乎缺失了。我可以解释这个问题。