yaquawa / jquery.photoswipe

The jQuery plugin for PhotoSwipe
91 stars 35 forks source link

Bind Photoswipe to another trigger #11

Closed ursbraem closed 7 years ago

ursbraem commented 7 years ago

Hi again!

In a project where I'm already using jquery.photoswipe for "regular" galleries (where you can click each thumbnail to open an image), I'd like to stick to your plugin for the following case also:

There's only a trigger button ("open gallery"). All the gallery's content is hidden. On click, the gallery launches.

Should I use jquery.photoswipe for that at all? If so, (how) would that work?

Or should I rather try to use the vanilla photoswipe directly? Can those two (vanilla pswp and your plugin) run alongside on the same page?

ursbraem commented 7 years ago

Here's my current quick & dirty solution...

$('#launch-gallery').on('click', function (e) {
  event.preventDefault();
  window.location.href += "#&gid=1&pid=1";
  location.reload();
});

... seen prettier things!

ursbraem commented 7 years ago

Unfortunately, my above ugly solution doesn't work with multiple galleries on a page (if you don't know which gallery it will be), as &gid changes

yaquawa commented 7 years ago

Hi ursbraem.

Try if this works.

$('#launch-gallery').on('click', function (e) {
    e.preventDefault();
    $('#hidden-gallery .thumbnail').eq(0).trigger('click');
});
ursbraem commented 7 years ago

Wohooo! Yes it does. I wrote the counter hard into the html, so this also worked:

$('#launch-gallery').on('click', function (e) {
    e.preventDefault();
    $('#hidden-gallery .thumbnail-0').trigger('click');
});

Thanks a lot!!!! So good.