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

<picture> tag support #37

Open
akhost opened this issue May 11, 2021 · 1 comment
Open

<picture> tag support #37

akhost opened this issue May 11, 2021 · 1 comment

Comments

@akhost
Copy link

akhost commented May 11, 2021

I am trying to add support for webp image formats with jpg fallbacks. When I write my listener like this the lightbox works as intended:

window.addEventListener('load', (event) => {
    document.querySelectorAll('.modal').forEach(image => {
        image.addEventListener('click', e => {
            basicLightbox.create(`
                <img src="` + image.getAttribute('data-image') + `.jpg">
            `).show();
        });
    });
});

However, when I write my listener like this, the lightbox does not close when I click on the image, only when I click on the background, making the lightbox difficult to close:

window.addEventListener('load', (event) => {
    document.querySelectorAll('.modal').forEach(image => {
        image.addEventListener('click', e => {
            basicLightbox.create(`

                <picture>
                    <source src="` + image.getAttribute('data-image') + `.webp" type="image/webp" srcset="
                        ` + image.getAttribute('data-image') + `.webp
                    ">
                    <img src="` + image.getAttribute('data-image') + `.jpg" data-image="{{image.path}}" srcset="
                        ` + image.getAttribute('data-image') + `.jpg
                    ">
                </picture>
            `).show();
        });
    });
});

I imagine this has something to do with the <picture> tag. Any thoughts on why this would be happening? Thanks

@akhost
Copy link
Author

akhost commented May 11, 2021

Ah, I see #35, but it does not appear that this solved my issue, as it is still happening? Thanks

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

1 participant