我有一个新闻提要页面,其中不同的帖子以灯光滑块和灯光画廊的组合显示他们的图像。到目前为止,我已经使它适用于硬编码的帖子,但未能对动态生成的帖子做同样的事情。
这是我用于组合 lightgallery 和 lightslider 的代码
$('.lightSlider').each(function (index) {
$(this).lightSlider({
gallery: true,
item: 1,
loop: true,
slideMargin: 0,
thumbItem: 9,
onBeforeSlide: function (el) {
$('#counter' + index).text(el.getCurrentSlideCount());
},
onSliderLoad: function(el) {
el.lightGallery({
selector: '.lightgallery .lslide'
});
}
});
});
这是我正在使用的代码,用于在动态生成的帖子中组合 lightslider 和 lightgallery
HTML:
<button type="button" id="appendnewcontainer">Click me To create new slider</button>
<div id="fotoappendarea">
JavaScript:
$(document).ready(function(){
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-national-geographic-6873734-1600-1200.jpg",
"http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg"
];
var hiddenimages = "",
albumcover;
$("#appendnewcontainer").click(function() {
$("<span />", {
class : "container",
appendTo : $("#fotoappendarea"),
append : $("<span />", {
class : "imagecontiner",
html : "<a class='dfed' href=" + imagesarray[1] + "><img src='" + imagesarray[1] + "' class='_34'/></a>"
}).lightGallery()
});
});
});