Проверьте, загружается ли изображение (никакие ошибки) с jQuery

Используйте преобразование :

tst = pd.DataFrame({'demographic' : ['A', 'B', 'B', 'A', 'C', 'C'],
            'id_match' : ['101', '101', '201', '201', '26', '26']})

tst['num_unq'] = tst.groupby('demographic')['id_match'].transform('nunique')

print(tst)

Выход

  demographic id_match  num_unq
0           A      101        2
1           B      101        2
2           B      201        2
3           A      201        2
4           C       26        1
5           C       26        1

215
задан Brian Tompsett - 汤莱恩 20 August 2019 в 11:53
поделиться

3 ответа

Другая возможность - это инициировать события onload и/или onerror путем создания элемента изображения в памяти и установки его атрибута src в атрибут оригинального изображения src. Вот пример того, что я имею в виду:

$("<img/>")
    .on('load', function() { console.log("image loaded correctly"); })
    .on('error', function() { console.log("error loading image"); })
    .attr("src", $(originalImage).attr("src"))
;

Надеюсь, это поможет!

.
240
ответ дан 23 November 2019 в 04:19
поделиться

Этот работал хорошо для меня:)

$('.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');
});
0
ответ дан 23 November 2019 в 04:19
поделиться

Проверьте свойства complete и naturalWidth, в этом порядке.

https://stereochro.me/ideas/detecting-broken-images-js

function IsImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren’t downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (img.naturalWidth === 0) {
        return false;
    }

    // No other way of checking: assume it’s ok.
    return true;
}
222
ответ дан 23 November 2019 в 04:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: