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

Open gallery from other button? #474

Closed
ALTELMA opened this issue Oct 13, 2016 · 4 comments
Closed

Open gallery from other button? #474

ALTELMA opened this issue Oct 13, 2016 · 4 comments

Comments

@ALTELMA
Copy link

ALTELMA commented Oct 13, 2016

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

@sachinchoolur
Copy link
Owner

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');
});

@giangphoton
Copy link

giangphoton commented Jan 24, 2019

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:
` <script>
lightGallery(document.getElementById('lightgallery'));

$(document).ready(function() {
$('#zoom-btn').on('click', function() {
$('#item1').trigger('click');
});
});
</script>`

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

Thanks,
Giang

@fhdalikhan
Copy link

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:
` <script>
lightGallery(document.getElementById('lightgallery'));

$(document).ready(function() {
$('#zoom-btn').on('click', function() {
$('#item1').trigger('click');
});
});
</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.

@surfer77
Copy link

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);
})

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

5 participants