Forked from Onepo1ntFive/js. Init-Destroy Owl Carousel 2
Created
August 26, 2019 11:14
-
-
Save Vterebenin/0195b92cd64c1b2fcc4e9b7747b6d518 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function initAdaptiveOwlCarousel(block, options, breakPoint, modClass) { | |
| windowWidth = window.innerWidth; | |
| modClass = typeof modClass !== 'undefined' ? modClass += " owl-carousel" : "owl-carousel"; | |
| if ( windowWidth < breakPoint ) { | |
| block.each(function(el) { | |
| $(this).addClass(modClass).owlCarousel(options); | |
| }) | |
| } else { | |
| block.each(function(el) { | |
| $(this).trigger("destroy.owl.carousel").removeClass(modClass); | |
| }) | |
| } | |
| } | |
| // init some carousel | |
| if ( $(".js-block").length ) { | |
| var windowWidth = window.innerWidth; | |
| var $owlCarousel = $(".js-block"); | |
| var owlOptions = { | |
| /* some stuff */ | |
| }; | |
| initAdaptiveOwlCarousel($owlCarousel, owlOptions, 1240, "owl-carousel-mod-class"); | |
| $(window).on("resize", function() { | |
| initAdaptiveOwlCarousel($owlCarousel, owlOptions, 1240, "owl-carousel-mod-class"); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment