Trying to build a jquery cycle2 carousel which loads extra slides on 'cycle-finished' but the extra slides a added wrong and the carousel dont proceed.
JSFiddle example here My HTML:
<div id="instagramSlides">
<div class="item"><h1>1</h1></div>
<div class="item"><h1>2</h1></div>
<div class="item"><h1>3</h1></div>
<div class="item"><h1>4</h1></div>
My Javascript:
$('#instagramSlides').cycle({
loop: 1,
fx: 'carousel',
carouselVisible: 4,
slides: 'div'
});
$('#instagramSlides').on('cycle-finished', function (event, opts) {
for (var i = 5; i < 10; i++) {
var content = ["<div class=\"item\"><h1>" + i + "</h1></div>"];
$('#instagramSlides').cycle('add', content);
}
});
Try 1:
var c_opt = {
loop: 0,
fx: 'carousel',
carouselVisible: 3,
slides: 'div.item'
};
$('#instagramSlides').cycle(c_opt);
$('#instagramSlides').on('cycle-after', function (event, opts) {
if (opts.nextSlide === 0) {
$(this).cycle('destroy');
$.ajax({
url: "/Home/Instagram20",
type: "POST",
data: { maxId: null },
dataType: "json",
success: function (data) {
var info = $.parseJSON(data);
for (var i = 5; i < 10; i++) {
var content = "<div class=\"item\"><img width=\"200\" height=\"200\" src=\"" + info['data'][i]['images']['thumbnail']['url'] + "\" /></div>";
$('#instagramSlides').append(content);
}
}
});
$(this).cycle(c_opt);
}
});
if I add them as this:
$('.cycle-carousel-wrap').append(content);
there are added just fine but are not part of the slideshow