Closed dyegonery closed 3 years ago
For others that might come across this, I have it mostly working by placing the .slide() call inside an event handler so it only fires after the gallery has openend. But there is a bug that the slide direction is wrong for the first arrow press :(. Will look into that later.
lg.addEventListener(
'onAfterOpen',
function() {
window.lgData[lg.getAttribute('lg-uid')].slide(2);
},
false
);
This is the final version and it fixes the issue I had with the slide direction being wrong.
lg.addEventListener(
'onAfterOpen',
function() {
window.lgData[lg.getAttribute('lg-uid')].slide(Number(slide));
window.lgData[lg.getAttribute('lg-uid')].index = Number(slide);
},
{
once: true
}
);
You can try
let el = document.getElementById('lightgallery');
lightGallery(el);
el.firstElementChild.click()
You can use dynamic mode to programmatically open the gallery and use lightGallery slide public method to go to a specific slide Dynamic mode demo - https://sachinchoolur.github.io/lightgallery.js/demos/dynamic.html Public method docs - https://sachinchoolur.github.io/lightgallery.js/docs/api.html#methods Public method demo - https://sachinchoolur.github.io/lightgallery.js/demos/methods.html
Please let me know if you have any questions
I tried running the slide() method to open the gallery programmatically, but it doesn't seem to work. Here's my code:
let el = document.getElementById('lightgallery'); window.lgData[el.getAttribute('lg-uid')].slide(1);
Is there any other way to accomplish this?