我从firefox获得了这个错误:
TypeError: $(...).lightGallery(...).destroy is not a function我使用下面的插件播放视频和显示图片库https://github.com/sachinchoolur/lightGallery。
我希望重新初始化lightGallery,因为我使用ajax在容器中动态添加元素。它在以前的lightGallery版本中运行得很好,但是它不能处理当前的版本。
我正在使用以下代码。
// destroy previous gallery
$("#lightGallery2").lightGallery({
selector : '.image_gallery',
videojs: true,
download: false
}).destroy();
// re-initialize
$("#lightGallery2").lightGallery({
selector: '.image_gallery',
videojs: true,
download: false
});请建议一下。
谢谢
发布于 2016-06-20 18:47:24
以下代码适用于我:
$lg.on('onBeforeClose.lg',function(event, index, fromTouch, fromThumb){
try{$lg.data('lightGallery').destroy(true);}catch(ex){};
});发布于 2016-03-29 18:41:06
要销毁数据,您应该向库中添加数据属性,然后销毁它,例如,如果将图库应用于所有链接:
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"]'});
};然后:
$( myGallery ).data('lightGallery').destroy(true);
lightgallery();发布于 2015-09-18 11:19:36
如果它是像大多数插件/小部件一样编写的,那么您应该像下面这样调用破坏方法。
$("#lightGallery2").lightGallery("destroy");https://stackoverflow.com/questions/32650578
复制相似问题