sachinchoolur / lightgallery.js

Full featured JavaScript image & video gallery. No dependencies
https://sachinchoolur.github.io/lightgallery.js/
Other
5.3k stars 596 forks source link

Events don't work #108

Closed Findus23 closed 6 years ago

Findus23 commented 6 years ago

Hi,

I have tried adding lightgallery to my site and it works really well. But there is one issue left: I can't get events to work.

Reading the docs it seems like the following should work, but while the gallery displays fine, nothing gets logged.

<div id="galleryElement"></div>
var galleryElement = document.getElementById("galleryElement");

var els = [{
    src: "https://sachinchoolur.github.io/lightgallery.js/static/img/1-1600.jpg"
}];
galleryElement.addEventListener("lgOnBeforeClose", function () {
    alert("closed");
});
galleryElement.addEventListener("lgOnBeforeOpen", function (e) {
    alert("onBeforeOpen");
}, false);

lightGallery(galleryElement, {
    dynamic: true,
    dynamicEl: els
});

Codepen for reproducing: https://codepen.io/anon/pen/MqwYoN

Findus23 commented 6 years ago

Turns out that unlike the examples in the docs, the events are called onBeforeClose and onBeforeOpen.

tomhalley commented 5 years ago

Well the documentation is out of date, so this shouldn't be closed.

Also having to deal with these events, and I can't even get onBeforeClose and onBeforeOpen working on my project:

const lightGalleryElement = document.getElementById('Gallery');

lightGalleryElement.addEventListener('onBeforeOpen', function() {
    console.log('Hello World');
});
taras2358 commented 5 years ago

In case someone experiences the same issue: https://sachinchoolur.github.io/lightGallery/docs/api.html#events