Skip to content

Use Glightbox in webcomponent #496

Answered by gingerchew
Lefthandmedia asked this question in Q&A
Discussion options

You must be logged in to vote

You're exactly right, the selector option is for the usual "on init, find these elements to use as slides." If you don't pass a selector, it will search for the default one (.glightbox if I remember right).

I may have accidentally misled you, setElements doesn't mark the elements pass in as triggers for the lightbox but as slides inside the lightbox. You'd need to add a little event handling:

window.customElements.define('my-lightbox', class extends HTMLElement {
	handleEvent({ type, target }) {
		if (type === 'click' && target.closest('.my-trigger')) {
			this.constructor._lightbox.open();
			// Or if you want to open at a certain index use openAt with the index of the slide
		}
    }

	c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Lefthandmedia
Comment options

@gingerchew
Comment options

Answer selected by Lefthandmedia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants