Yup, you got it right, once you have added the new element, all you need to do is reinitialize the mySwipe object.
This is the first initialization of the swipe slider object:
/*----------------------------------------
Swipe slider to enable touch sliding
----------------------------------------*/
document.mySwipe = new Swipe(document.getElementById('slider'), {
startSlide: 0,
speed: 400,
auto: 5000,
callback: function(event, index, elem) {
// do something cool
}
});
Now just define a method which re-initializes the swipe object.
/*----------------------------------------
Reinitializing the Swipe Slider.
----------------------------------------*/
document.reinit = function(){
document.mySwipe = new Swipe(document.getElementById('slider'), {
startSlide: 0,
speed: 400,
auto: 5000,
callback: function(event, index, elem) {
// do something cool
}
});
}
Call that method when you have finished adding new elements to the existing slider.
// Finished adding new elements
document.reinit();