luis-almeida / unveil

A very lightweight jQuery plugin to lazy load images
4.16k stars 676 forks source link

sometimes the images aren't loaded and browser shows error icon until the page is scrolled #151

Open paolobenve opened 5 years ago

paolobenve commented 5 years ago

If I visit a page and scroll so that all images unveil, then go to other page and come back to the first, images are already in browser cache, so it seems that unveil isn't triggered again, and the browser shows the error icon.

Is there any work around?

paolobenve commented 5 years ago

Well, I checked more specifically, it's not for the cache...

What is then the reason of this behaviour?

paolobenve commented 5 years ago

I modified the title: the problem is that, randomlessly, some visible image isn't unveiled until the page is scrolled. Why?

jakmedia commented 5 years ago

I get the same behavior when using jQuery 3.3.1. It works as expected on older versions of jQuery for me. I'm not sure how to fix this though.

jakmedia commented 5 years ago

SOLVED – If you are using jQuery 3.3.1 you need to change the second line of your Javascript code.

$("img").unveil(200, function() { $(this).load(function() { this.style.opacity = 1; }); });

Change the line of code in bold above to this:

$(this).on('load', function() {

Worked for me. No more Javascript errors in the browser.