Check if an image is loaded (no errors) with jQuery

前端 未结 15 1359
挽巷
挽巷 2020-11-21 20:45

I\'m using JavaScript with the jQuery library to manipulate image thumbnails contained in a unordered list. When the image is loaded it does one thing, when an error occurs

15条回答
  •  自闭症患者
    2020-11-21 21:10

    This one worked fine for me :)

    $('.progress-image').each(function(){
        var img = new Image();
        img.onload = function() {
            let imgSrc = $(this).attr('src');
            $('.progress-image').each(function(){
                if($(this).attr('src') == imgSrc){
                    console.log($(this).parent().closest('.real-pack').parent().find('.shimmer').fadeOut())
                }
            })
        }
        img.src = $(this).attr('src');
    });
    

提交回复
热议问题