1

Here is my function

var img = new Image();

$(img).load(function () {

    $(this).css('display','none');

    $(el).removeClass('loading').append(this);

    $(this).fadeIn();

}).error(function () {
    $(el).remove();
}).attr('src', srcImage);

I need to get the width of the loaded image or srcImage

I can do this with

var w = $('.parent_element').find('img').css('width');

but it needs to be done after srcImage is completely loaded

4

2 回答 2

0

我不确定,但尝试一下。

来自 jQuery:

示例:将类 bigImg 添加到每个图像加载时高度大于 100 的所有图像。

$('img.userIcon').load(function(){
    if($(this).height() > 100) {
        $(this).addClass('bigImg');
    }
});

资源

于 2013-05-17T23:44:16.747 回答
0

使用 Jquery 图片加载插件

//Initially hide the image with CSS
visibility: hidden

//container holding your images
$('.photos').imagesLoaded(function () {
    //Function to measure size

    //Take measurements
    var w = $('img').width();
    var h = $('img').height();

    //Once you know the proper size, show it
    $('img').show();              
});
于 2013-05-18T00:01:34.420 回答