调整jQuery中的图像大小不适用于所有图像



我希望它扩展td img.standingslogo的所有实例,但它无法正常工作

jsfiddle -https://jsfiddle.net/ze5ebnw7/13/

$(window).load(function(){
    image = []
    $('td img.standingslogo').each(function() {
        imageWidth = $(this).width();
        image[$(this).index()] = imageWidth;
    });
    $(window).resize(function() {
        $('td img.standingslogo').hide();
        $('td img.standingslogo').each(function() {
            tdWidth = $(this).parent().width();
            imgWidth = image[$(this).index()];
            if (imgWidth>=tdWidth) {$(this).css({width:tdWidth});} else {$(this).css({width:imgWidth});}
            $(this).show();
        });
    }).resize();
});

现在工作

$(window).load(function(){
image = [];
i=0;
$('.standingslogo').each(function() {
    imageWidth = $(this).width();
    image[i] = imageWidth;
    i++
});
$(window).resize(function() {
    $('.standingslogo').hide();
    i=0;
    $('.standingslogo').each(function() {
        tdWidth = $(this).parent().width();
        imgWidth = image[i];
        if (imgWidth>=tdWidth) {$(this).css({width:tdWidth});} else {$(this).css({width:imgWidth});}
        $(this).show();
        i++
    });
}).resize();
});

最新更新