[英]How to destroy and re-initialise lightgallery.js
I am using lightgallery on my page, which is working fine.我在我的页面上使用 lightgallery,效果很好。 I have added a filter function to the gallery, so now need to destroy and rebuild my lightgallery to reflect the change in the gallery content.
我已经向画廊添加了过滤器 function,所以现在需要销毁并重建我的光画廊以反映画廊内容的变化。 I have this so far:
到目前为止我有这个:
source.js源码.js
import 'lightgallery.js';
var gallery = document.getElementById('gallerywrapper');
if(gallery) {
lightGallery(gallery, {
download: false,
counter: false,
selector: '.item.active'
});
}
var galleryFilterButtons = document.querySelectorAll('.gallery-filter-button');
for(var i = 0; i<galleryFilterButtons.length; i++) {
galleryFilterButtons[i].addEventListener("click", function(){
// destroy and rebuild here...
});
}
I can't get the destroy function to work at all, can anyone give any pointers?我根本无法让销毁 function 工作,有人可以指点一下吗?
The documentation shows that you can destroy with this: 该文档显示您可以使用以下方法进行销毁:
window.lgData[gallery.getAttribute('lg-uid')].destroy(true);
and then just init again.然后再次初始化。 So in your case it would be:
因此,在您的情况下,它将是:
for (var i = 0; i < galleryFilterButtons.length; i++) {
galleryFilterButtons[i].addEventListener("click", function(){
window.lgData[gallery.getAttribute('lg-uid')].destroy(true);
lightGallery(gallery);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.