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

Only accept direct child imgs when determing If picture is loaded #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RevisionTen
Copy link

Otherwise it won't work If the picture element has a fallback img inside of a script tag (the img in the script tag is selected and no new img element is appended to the picture element).

This fix is needed when dynamically adding picture elements with fallback img in a noscript tag.

…een loaded before

Otherwise it won't work If the picture element has a fallback img inside of a script tag (the img in the script tag is selected and no new img element is appended to the picture element).
@RevisionTen
Copy link
Author

Maybe this can also be fixed with a call to isLoaded instead.

@ApoorvSaxena
Copy link
Owner

@RevisionTen can you please share a codepen example where the existing implementation fails?

@RevisionTen
Copy link
Author

RevisionTen commented Oct 2, 2020

@ApoorvSaxena Sure, heres an example where it fails with an img inside a noscript:
https://jsfiddle.net/k4bzp596/

Heres the same code but without the noscript fallback img:
https://jsfiddle.net/7L9qzfwk/

I ran into this problem with a site where I load content containing lozad pictures via ajax for visitors that have javascript enabled (visitors without javascript are just opening a new page instead of dynamically loading the content).
A simple workaround was to just remove the noscript element before inserting the picture elements into the DOM (they don't need them anyways because they obviously have javascript enabled).

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

Successfully merging this pull request may close these issues.

None yet

2 participants