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

Lightense on lazy loaded images #56

Closed
bkistyping opened this issue Mar 25, 2021 · 0 comments
Closed

Lightense on lazy loaded images #56

bkistyping opened this issue Mar 25, 2021 · 0 comments
Assignees

Comments

@bkistyping
Copy link

bkistyping commented Mar 25, 2021

I'm trying to use Lightense on a page where some images are lazy loaded when a toggle is opened. I have a window.addEventListener('load' set up on the page generally, and am calling Lightense() on the images when they are loaded in.

The issue I'm seeing is that multiple instances of Lightense() break because the !d.querySelector('.lightense-backdrop') check causes config.container to be undefined:

Uncaught TypeError: Cannot read property 'removeEventListener' of undefined
    at unbindEvents (lightense.js:366)
    at removeViewer (lightense.js:299)
    at init (lightense.js:337)
    at HTMLImageElement.<anonymous> (lightense.js:193)

My solution is to set config.container to the already existing backdrop:

if (!d.querySelector('.lightense-backdrop')) {
  ...
} else {
  config.container = d.querySelector('.lightense-backdrop');
}

This fix works great, but I wanted to call it out and ask if there was a better solution to this general problem than what I'm doing. Thanks!

@sparanoid sparanoid self-assigned this Jun 30, 2021
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

No branches or pull requests

2 participants