简体   繁体   English

类型错误:$(...).lightGallery(...).destroy 不是函数

[英]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");

You have to use the following method to destroy lightgallery version 1.2.x. 您必须使用以下方法来销毁lightgallery 1.2.x版。

var $lg = $('#lightGallery2');

$lg.lightGallery({
  selector : '.image_gallery',
  videojs: true,
  download: false
});

$lg.data('lightGallery').destroy(true);

Here is the docs 这是文档

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.

相关问题 使用 lightGallery 和 Jekyll:TypeError: $(...).lightGallery is not a function - using lightGallery and Jekyll: TypeError: $(...).lightGallery is not a function 未捕获的TypeError:$(...)。lightGallery不是一个函数 - Uncaught TypeError: $(…).lightGallery is not a function 视频库得到 Uncaught TypeError: $(...).lightGallery is not a function - video gallery getting Uncaught TypeError: $(...).lightGallery is not a function lightgallery typeError图片无法加载? - lightgallery typeError images not loading? 将事件侦听器停止在“ $ destroy”上。 TypeError:$ on不是函数; - Stop event listeners on '$destroy'. TypeError: $on is not a function; 未被捕获的TypeError:binding.destroy不是ExtJs 5中的函数 - Uncaught TypeError: binding.destroy is not a function in ExtJs 5 如何销毁和重新初始化 lightgallery.js - How to destroy and re-initialise lightgallery.js UnhandledPromiseRejectionWarning: TypeError: user.destroy is not a function (NodeJS- Sequelize) - UnhandledPromiseRejectionWarning: TypeError: user.destroy is not a function (NodeJS- Sequelize) 如何在lightgallery onCloseAfter.lg方法中调用js function? - how to call js function in lightgallery onCloseAfter.lg method? $ 未定义灯廊 - $ is not defined lightgallery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM