Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterLoad event not always triggered on background-images #206

Open
dominicht opened this issue Jul 15, 2019 · 2 comments
Open

afterLoad event not always triggered on background-images #206

dominicht opened this issue Jul 15, 2019 · 2 comments
Assignees
Labels

Comments

@dominicht
Copy link

dominicht commented Jul 15, 2019

I'm using this plugin to lazy load <img> and background images. I use the afterLoad event to add a class to the element so that I can trigger some CSS animation. This works fine most of the time (about 90% of the time), but here and there the event simply doesn't get triggered at all on some elements, even after successfully loading the image.

So far, this seems to be only an issue with background images.

This is the code I'm using:

$('.lazy').Lazy({
    threshold: $(window).width() > 767 ? 500 : 50,
    afterLoad: function(element) {
        element.addClass('lazy-loaded');
    }
  });

Update
I wanted to a quick ugly workaround with beforeLoad and realized beforeLoad also doesn't get triggered here and there. It seems like all the events/callbacks aren't working properly with background images.

I also noticed that when the issue happens and I have a full row of multiple elements with background images, the full row won't have the events triggered. It seems to be an issue related to the viewport more than a single element.

@dkern dkern self-assigned this Sep 4, 2019
@dkern dkern added the question label Sep 4, 2019
@dkern
Copy link
Owner

dkern commented Sep 4, 2019

I need to check this.

@yCodeTech
Copy link

yCodeTech commented Jan 30, 2020

I have a similar issue where the afterLoad callback doesn't trigger ALL the time. But my problem occurs on normal <img>'s.

The internal fadeIn effect clashes with my CSS transition, so I've had to apply a CSS opacity: 0; to my img, and then set the opacity with a transitioning effect of my own using the afterLoad callback so that the background colour of the parent container is visible through the image.

There is no reason why the callback occasionally doesn't work, it should work ALL the time with ALL lazy images.

afterLoad: function (element) {
	$(element).css("opacity", 0.1);
}

CSS:

.lazy {
    opacity: 0;
    transition: opacity 1s;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants