[英]TypeError: $(...).lightGallery(...).destroy is not a function
I am getting this error from firefox:我从 Firefox 收到此错误:
TypeError: $(...).lightGallery(...).destroy is not a function
I am using following plugin for play video and show image gallery https://github.com/sachinchoolur/lightGallery .我正在使用以下插件播放视频和显示图片库https://github.com/sachinchoolur/lightGallery 。
I want re-initialize lightGallery because I am using ajax to add element dynamically in container.我想重新初始化 lightGallery,因为我使用 ajax 在容器中动态添加元素。 It was working fine with previous version of lightGallery but it is not working with current version.它在以前版本的 lightGallery 上运行良好,但不适用于当前版本。
I am using following code.我正在使用以下代码。
// destroy previous gallery
$("#lightGallery2").lightGallery({
selector : '.image_gallery',
videojs: true,
download: false
}).destroy();
// re-initialize
$("#lightGallery2").lightGallery({
selector: '.image_gallery',
videojs: true,
download: false
});
Please suggest.请建议。
Thanks谢谢
The following code works for me: 以下代码对我有用:
$lg.on('onBeforeClose.lg',function(event, index, fromTouch, fromThumb){
try{$lg.data('lightGallery').destroy(true);}catch(ex){};
});
如果它是像大多数插件/小部件一样编写的,则应该这样调用destroy方法。
$("#lightGallery2").lightGallery("destroy");
For destroy data you should add data attribute to your gallery then destroy it, for example if you apply gallery to all links: 对于销毁数据,您应该将数据属性添加到图库中,然后销毁它,例如,如果您将图库应用于所有链接:
var myGallery = 'body',
lightgallery = function() {
$( myGallery ).attr('data-lightGallery', '1');
$( myGallery ).lightGallery({selector: 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"]'});
};
Then: 然后:
$( myGallery ).data('lightGallery').destroy(true);
lightgallery();
I simply created a global variable.我只是创建了一个全局变量。 It allows me to perform the desired function.它允许我执行所需的功能。
var PLUGIN; // global variable
...
if(PLUGIN) PLUGIN.data('lightGallery').destroy(true); // destroy
PLUGIN = $("#lightGallery2").lightGallery();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.