Text that will be inserted as the first slide:
And the code to do it:
$('button.insert').on('click', function() {
var curr = $.jCarouselLite.curr;
var newSlide = '<li class="slide prepended">' +
$('#to-prepend').html() +
'</li>';
// Insert the slide at the beginning
$slideshow.children('ul').prepend(newSlide);
// Trigger the refresh
// with the second argument set to ['all']
$slideshow.trigger('refreshCarousel', ['all']);
// Now, since the slide was inserted *before* the current one,
// we have to immediately adjust the carousel position
// if we want it to remain at the same slide.
//
// Add 1 to the current position for the new slide,
// and subtract 1 for *each* visible slide
// (because the carousel is circular and
// the plugin thus adds "padding" slides)
$slideshow
.trigger('go', [curr + 1 - 2, {speed: 0}]);
});
Text that will be inserted in a new slide after the first currently visible slide:
And the code to do it:
$('button.insert').on('click', function() {
var curr = $.jCarouselLite.curr;
var newSlide = '<li class="slide">' +
$('#to-insert').html() +
'</li>';
// Insert the slide after the current slide
$slideshow.find('li.slide').eq(curr)
.after(newSlide);
// Trigger the refresh
// with the second argument set to ['all']
$slideshow.trigger('refreshCarousel', ['all']);
});