Skip to content

Instantly share code, notes, and snippets.

@Korveld
Created August 2, 2024 10:26
Show Gist options
  • Save Korveld/91297ca9b615fade603698b485c55329 to your computer and use it in GitHub Desktop.
Save Korveld/91297ca9b615fade603698b485c55329 to your computer and use it in GitHub Desktop.
Slick slider on mobile only
/* Slick needs no get Reinitialized on window Resize after it was destroyed */
$(window).on('load resize orientationchange', function() {
$('.carousel').each(function() {
var $carousel = $(this);
/* Initializes a slick carousel only on mobile screens */
// slick on mobile
if ($(window).width() > 768) {
if ($carousel.hasClass('slick-initialized')) {
$carousel.slick('unslick');
}
}
else {
if (!$carousel.hasClass('slick-initialized')) {
$carousel.slick({
slidesToShow: 2,
slidesToScroll: 1,
mobileFirst: true,
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment