Skip to content

Instantly share code, notes, and snippets.

@robinbastien
Last active August 29, 2015 14:16
Show Gist options
  • Save robinbastien/43f040b323524ad43e56 to your computer and use it in GitHub Desktop.
Save robinbastien/43f040b323524ad43e56 to your computer and use it in GitHub Desktop.
Owl Carousel Reset on Resize
jQuery(document).ready(function($) {
// When user resizes window...
$(window).on('resize',function() {
// Set interval until timer is cleared, indicating end of the resize event
waitForFinalEvent(function() {
// Get owl carousel
var owldata = $(".owl-carousel").data('owlCarousel');
// Use the owl Carousel's reset method
owldata.updateVars();
}, 200, "OwlCarouselResizeReset");
});
});
var waitForFinalEvent = (function () {
var timers = {};
return function (callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Don't call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout (timers[uniqueId]);
}
timers[uniqueId] = setTimeout(callback, ms);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment