I have a news feed page where different posts show their images in a combination of lightslider and lightgallery. So far I have made it work for hardcoded posts, but failing to do the same for posts that are dynamically generated.
Here is the code I'm using for combining lightgallery and 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'
});
}
});
});
Here is the code I am playing with for combining lightslider and lightgallery in dynamically generated posts
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()
});
});
});
Solved! Here is how I did it
HTML:
JavaScript:
Will add the jsfiddle later