Skip to content

Instantly share code, notes, and snippets.

@sarvar
Created June 12, 2022 16:22
Show Gist options
  • Save sarvar/f1dfb3f70f0f43adab8c1da04a222368 to your computer and use it in GitHub Desktop.
Save sarvar/f1dfb3f70f0f43adab8c1da04a222368 to your computer and use it in GitHub Desktop.
owl-carousel only for mobile
/*
And a bit of CSS to show disabled Owl element:
.owl-carousel.off {
display: block;
}
*/
$(function() {
var owl = $('.owl-carousel'),
owlOptions = {
loop: false,
margin: 30,
smartSpeed: 700,
nav: false,
items: 1
};
if ( $(window).width() < 768 ) {
var owlActive = owl.owlCarousel(owlOptions);
} else {
owl.addClass('off');
}
$(window).resize(function() {
if ( $(window).width() < 768 ) {
if ( $('.owl-carousel').hasClass('off') ) {
var owlActive = owl.owlCarousel(owlOptions);
owl.removeClass('off');
}
} else {
if ( !$('.owl-carousel').hasClass('off') ) {
owl.addClass('off').trigger('destroy.owl.carousel');
owl.find('.owl-stage-outer').children(':eq(0)').unwrap();
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment