Created
August 2, 2024 10:26
-
-
Save Korveld/91297ca9b615fade603698b485c55329 to your computer and use it in GitHub Desktop.
Slick slider on mobile only
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
/* 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