PhotoSwipe:有没有一种方法可以将事件处理程序附加到"init"事件,或者当插件打开灯箱时? [英] PhotoSwipe: Is there a way to attach an event handler to the 'init' event or when the plugin opens the lightbox?

查看:129
本文介绍了PhotoSwipe:有没有一种方法可以将事件处理程序附加到"init"事件,或者当插件打开灯箱时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 PhotoSwipe 灯箱与

I'm using PhotoSwipe lightbox in conjuntion with Slick carousel for a project, and I want to have the carousel autoplay while the photoswipe lightbox is not open, but when the lightbox is opened, I want the autoplay to stop.

PhotoSwipe API 中,它们具有一个closedestroy事件来监听,但不是initopen的事件.有没有人找到这样做的好方法?

In the PhotoSwipe API they have a close and destroy event to listen for, but not an event for init or open. Has anyone found a good way to do this?

类似的东西:

$('#gallery').slick({
  autoplay: true,
  dots: true,
});

// ... Setup photoswipe...

pswp.listen('open', function() {
  $('#gallery').slickSetOption('autoplay', false, false);
});

pswp.listen('close', function() {
  $('#gallery').slickSetOption('autoplay', true, false);
});

pwsp.init();

推荐答案

因此,我发现您可以在初始化之前执行所需的操作,然后在close上附加事件处理程序.

So to do this, I found that you can just do what you need to do before init, then attach an event handler on close.

Slick还存在一个问题,即从1.3.15版开始,无法使用slickSetOption命令关闭自动播放功能.

Also there's an issue with Slick where the autoplay doesn't turn off using the slickSetOption command as of version 1.3.15.

https://github.com/kenwheeler/slick/issues/731

这是我针对此问题的评论之一的解决方法:

Here is my workaround for it based on one of the comments on the issue:

// ... Setup PhotoSwipe ...
slider.slickPause();
slider.find('.slick-list').off('mouseleave.slick');

gallery.listen('close', function() { 
  slider.slickPlay();
  slider.find('.slick-list').on('mouseleave.slick', function() {
    slider.slickPlay();
  });
});

gallery.init();   

这篇关于PhotoSwipe:有没有一种方法可以将事件处理程序附加到"init"事件,或者当插件打开灯箱时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆