Lightgallery: Open gallery from other button?

Created on 13 Oct 2016  ·  4Comments  ·  Source: sachinchoolur/lightGallery

I will finding solution for click button and open gallery and integrated from lightslider
I not sure It's possible to do like this.

Anyone can suggestion?
Thanks

Most helpful comment

Here is a snippet without using jquery in case anyone is looking for in the future:

document.querySelector(".startGalleryBtn").addEventListener('click', function() {
    var startGalleryEvent = new CustomEvent('click', {bubbles: true, cancelable: true});
    document.querySelector(".firstGalleryItem").dispatchEvent(startGalleryEvent);
})

All 4 comments

Hi,

Method 1:

Use lightGallery dynamic mode
Demo : http://sachinchoolur.github.io/lightGallery/demos/dynamic.html

Method 2:

Trigger click event with jQuery :

$('#mybutton').on('click', function() {
   $('.first-item').trigger('click');
});

Hi Sachin,

I tried to trigger click event with jQuery using Method 2 you mentioned above but it didn't work. Please review my code.

I have a Zoom icon with id "zoom-btn":
<div class="zoom-btn"> <span class="fa fa-search" aria-hidden="true"> </div>

For the script:
` `

I clicked on the button and it didn't run. Please give me some suggestions.

Thanks,
Giang

Hi Sachin,

I tried to trigger click event with jQuery using Method 2 you mentioned above but it didn't work. Please review my code.

I have a Zoom icon with id "zoom-btn":
<div class="zoom-btn"> <span class="fa fa-search" aria-hidden="true"> </div>

For the script:
` `

I clicked on the button and it didn't run. Please give me some suggestions.

Thanks,
Giang

You have a class name zoom-btn not an id, to reference a class use $('.zoom-btn') and for id use $('#zoom-btn') jquery selector.

Here is a snippet without using jquery in case anyone is looking for in the future:

document.querySelector(".startGalleryBtn").addEventListener('click', function() {
    var startGalleryEvent = new CustomEvent('click', {bubbles: true, cancelable: true});
    document.querySelector(".firstGalleryItem").dispatchEvent(startGalleryEvent);
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MatteoZorro picture MatteoZorro  ·  7Comments

ghost picture ghost  ·  8Comments

miedzikd picture miedzikd  ·  6Comments

hokutonanto picture hokutonanto  ·  7Comments

FDiskas picture FDiskas  ·  5Comments