I'm trying to use Jssor slider to show different HTML content depending on selected category and its subcategory. I successfully created content slider for one subcategory, but I can't figure out how can I destroy my current slider and recreate it with different content loaded with Ajax. Item count differs in subcategories, so as I understand - changing current slides is not an option.
So, my question is - how do I destroy current Jssor slider and make way for a new one?
I had the same requirement and after some head scratching got it to work (for my requirements at least).
Using .remove() method removes the selected element(s) and its child elements. Which removed all the slide markup inside this element.
As such when calling this, I needed to create and populate the basic child elements (again) and append to the container. $("#slider1_container").append(theOriginalHtmlMarkup).
Having done this I was able to repopulate the slider with the newly fetched data.
The old slider is still in ghosting mode and not really removed. A destroy() function is not added yet. The slider needs a $Pause and any event is to unbind before refreshing.
https://github.com/jssor/slider/issues/98
Jssor - unbinding the event
Don't try - it is mad. I thought that everything was solved until I used the keyboard for navigation. Without a destroy method I would not recommend to do it this way and leave uncollected garbage.
Please simply remove the slider container.
Expanding on to the approach by @Kai150...
<div id='slider1_container'>
. If you want, you could leave the initial slides container div empty, so you can dynamically build the slide deck from scratch:<div id ="slider1_slides" u="slides" ...></div>
var originalHTML = '...'
. Be careful to use single quotes, and that all the original HTML code uses double quotes (or vice versa).$('#slider1_container').remove();
$('body').append(originalHTML);
$('#slider1_container div').first().append(newSlideHTML);
wherenewSliderHTML
is minified HTML code to build another slide.new $JssorSlider$('slider1_container', options);
All this can be wrapped into some basic functionality through a script. Here's some sample functional code, using the thumbnail-5 version, where you call
refreshSlider
with an array of image objects: