我希望能够.load()
在创建元素 - 图像元素时执行函数的回调。该代码通过以下代码加载新的图像元素来工作:
$('<img />').load(function()
{
var img = this;
$('.block-wrap img').fadeOut('slow', function()
{
$(this).replaceWith(img);
});
}).attr('src', loadurl);
但是我希望在加载和替换图像后能够继续。这就是我需要它的工作方式:
$('<img />').load(function()
{
var img = this;
$('.block-wrap img').fadeOut('slow', function()
{
$(this).replaceWith(img);
});
}).attr('src', loadurl);
$('.block-wrap input.imageheight').val($('.block-wrap img').height());
$('.block-wrap input.imagewidth').val($('.block-wrap img').width());
它返回第一个图像高度(不是已被替换的图像,它是加载微调器图像),因此我需要它能够在图像完全加载到 DOM 时检索图像的高度和宽度。太糟糕.replaceWith()
了,没有回调方法,但我不能使用回调函数,.load()
因为它是一个通过函数传递的函数,所以它.load()
不起作用。