Last active
August 29, 2015 14:16
-
-
Save robinbastien/43f040b323524ad43e56 to your computer and use it in GitHub Desktop.
Owl Carousel Reset on Resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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