我正在使用我的网站上的light gallery插件,同时运行
$('#categoryImages').lightGallery().destroy(true);
我收到控制台错误
Uncaught TypeError:$(...)。lightGallery(...)。destroy不是函数
下面提到的代码段是我用于光库的网站代码。
$subcategory) { $subcategoryImage= scandir($dir.strtolower($getCategory)."/".$subcategory); unset($subcategoryImage[array_search('.', $subcategoryImage, true)]); unset($subcategoryImage[array_search('..', $subcategoryImage, true)]); foreach ($subcategoryImage as $key => $value2) { $data['subcategoryImages'][]= $dir.strtolower($getCategory)."/".$subcategory."/".$value2;?>
<li class="col-xs-6 col-sm-4 col-md-3" data-responsive=" 375, 480," data-src="">
<img class="img-responsive" src="">
Jquery代码
$('body').on('click', '.category', function() {
$('#categoryImages').lightGallery().destroy(true);
});
答案 0 :(得分:1)
正如文档那样:http://sachinchoolur.github.io/lightGallery/docs/api.html#methods
var cI = $('#categoryImages');
cI.lightGallery();
$('body').on('click', '.category', function() {
cI.data('lightGallery').destroy(true);
});
答案 1 :(得分:1)
你需要保存对初始化插件的引用,然后在ajax完成后调用destroy,在你调用destroy后重新初始化插件
var gal = $('#categoryImages');
gal.lightGallery();
/...
request.done(function(data) {
//...
$('.ajxcategoryImages').html(subcategoryImages1); //append the results
gal.data('lightGallery').destroy(true);//destroy the current gallery
gal.lightGallery();//create a new one
/..