Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript lightgallery不适用于动态生成的元素_Javascript_Jquery_Html_Css_Lightgallery - Fatal编程技术网

Javascript lightgallery不适用于动态生成的元素

Javascript lightgallery不适用于动态生成的元素,javascript,jquery,html,css,lightgallery,Javascript,Jquery,Html,Css,Lightgallery,我已经实现了lighgallery插件到我的本地网站。。。这不适用于dom元素 比如说 1.)将用js创建的dom元素附加到html代码中 如果我在js“中创建了类似的东西,并且所有的代码都在一个变量中,那么让我们调用galleryview(var galleryview),这个变量我附加到html文件中的一个div中,并从js文件code$(“.container”)中这样附加

我已经实现了lighgallery插件到我的本地网站。。。这不适用于dom元素

比如说

1.)将用js创建的dom元素附加到html代码中

如果我在js
中创建了类似的东西,并且所有的代码都在一个变量中,那么让我们调用galleryview(
var galleryview
),这个变量我附加到html文件
中的一个div中,并从js文件code
$(“.container”)中这样附加$(“.imgcon”).lightGallery()不工作

这里没有使用dom

2.)图像采用html代码

我有这样的html代码
这很好用。
$(.imgcon”).lightGallery()

这里没有dom

问题:为什么我不能将dom与lightgallery一起使用

第一个演示不起作用,因为我使用js dom,第二个演示起作用,因为我在html文件中使用html代码。。或者我的代码有任何问题。

只需将您的
$(“.imagecontiner”).lightGallery()放入即可内部单击
处理程序

上述内容仅适用于动态创建的第一个gellery。
要使其适用于多个元素:预先创建内存中可追加的元素,并将
.lightGallery()实例分配给每个元素

$(文档).ready(函数(){
var imagesarray=[
"http://www.planwallpaper.com/static/images/Winter-Tiger-Wild-Cat-Images.jpg",
"http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg",
"http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg",
"http://i765.photobucket.com/albums/xx291/just-meller/national%20geografic/Birds-国家地理-6873734-1600-1200.jpg“,
"http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg"
];
var hiddenimages=“”,
唱片封面;
$(“#appendnewcontainer”)。单击(函数(){
$("", {
类别:“容器”,
附件:$(“#fotoappenderea”),
附加:$(“”){
类:“imagecontiner”,
html:“
}).lightGallery()号
});
});
});

当您在之后生成库项目时,您需要在项目中使用以下代码

    var $methods = $('#gallery-container');

$methods.lightGallery();
$methods.data('lightGallery').destroy(true);
$methods.lightGallery({
    thumbnail: true,
    animateThumb: true,
    showThumbByDefault: true,
});

是的,我写得很快,所以我写了缩写,是什么?什么意思?好的,顺便说一句,你明白qeustion了吗?或者我必须解释一下??你总是在数组中附加
[1]
第个图像。。。所以我不明白你的问题是什么。从数组来看没关系。。。我想知道为什么第一个代码不适用于lightgallery?为什么我应该在@Phoenix中使用?上面的内容只适用于第一个附加,对于多个附加,请稍等片刻以改进我的回答:Dok这对我有效,但这对每个附加项也有效@Phoenix如果您附加了多个,第二个,第三个etc不可点击,也就是说:不会进入图库。将我的扩展答案示例用于多个动态库。@Phoenix ohh以及:D
    var $methods = $('#gallery-container');

$methods.lightGallery();
$methods.data('lightGallery').destroy(true);
$methods.lightGallery({
    thumbnail: true,
    animateThumb: true,
    showThumbByDefault: true,
});