Last active
April 17, 2023 09:44
-
-
Save kirandash/fa0f6e131b2cd425f02a4da099e42458 to your computer and use it in GitHub Desktop.
Owl Carousel Destroy on desktop and Initialize on mobile
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 postsCarousel() { | |
var checkWidth = $(window).width(); | |
var owlPost = $("#latest-posts .posts-wrapper"); | |
if (checkWidth > 767) { | |
if (typeof owlPost.data('owl.carousel') != 'undefined') { | |
owlPost.data('owl.carousel').destroy(); | |
} | |
owlPost.removeClass('owl-carousel'); | |
} else if (checkWidth < 768) { | |
owlPost.addClass('owl-carousel'); | |
owlPost.owlCarousel({ | |
items: 1, | |
slideSpeed: 500, | |
animateOut: 'fadeOut', | |
touchDrag: false, | |
mouseDrag: false, | |
autoplay: true, | |
autoplaySpeed: 8000, | |
autoplayTimeout: 8000, | |
dots: true, | |
loop: true | |
}); | |
} | |
} | |
postsCarousel(); | |
$(window).resize(postsCarousel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@andyiwest Glad it helped!