For some reason, $ ('# your_carousel'). trigger ('destroy.owl.carousel') does not work correctly. it does not remove all classes that are needed to recreate the plugin.
You will need to remove them completely to destroy the "Owl Carousel 2". as described here in this release on github: https://github.com/smashingboxes/OwlCarousel2/issues/460
To destroy the owl function, use:
$('#your_carousel').trigger('destroy.owl.carousel').removeClass('owl-carousel owl-loaded'); $('#your_carousel').find('.owl-stage-outer').children().unwrap();
This worked fine for me:
// find element $owl = $('body').find('#your_carousel'); // set the owl-carousel otions var carousel_Settings = { touchDrag: false, mouseDrag: false }; function initialize(){ var containerWidth = $('body').find('.navbar').outerWidth(); if(containerWidth <= 767) { // initialize owl-carousel if window screensize is less the 767px $owl.owlCarousel( carousel_Settings ); } else { // destroy owl-carousel and remove all depending classes if window screensize is bigger then 767px $owl.trigger('destroy.owl.carousel').removeClass('owl-carousel owl-loaded'); $owl.find('.owl-stage-outer').children().unwrap(); } } // initilize after window resize var id; $(window).resize( function() { clearTimeout(id); id = setTimeout(initialize, 500); }); // initilize onload initialize();
Daniel
source share