Created
October 8, 2020 17:01
-
-
Save ShuvoHabib/776605758bc290ffb35e73b7a4a5a18f to your computer and use it in GitHub Desktop.
Slick Slider for Mobile Only
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
var slickSliderActive = false; | |
function checkSlider(){ | |
if( $(window).width() < 768 - getScroll() ) { | |
if(slickSliderActive == false) { | |
$('#video-wrap').slick({ | |
dots: false, | |
slidesToShow: 1, | |
slidesToScroll: 1 | |
}); | |
slickSliderActive = true; | |
} | |
} | |
else { | |
if(slickSliderActive == true) { | |
$('#video-wrap').slick('unslick'); | |
slickSliderActive = false; | |
} | |
} | |
}; | |
checkSlider(); | |
$(window).on('resize', function(){ | |
checkSlider(); | |
}); | |
function getScroll(){ | |
var div = document.createElement('div'); | |
div.style.overflowY = 'scroll'; | |
div.style.width = '50px'; | |
div.style.height = '50px'; | |
div.style.visibility = 'hidden'; | |
document.body.appendChild(div); | |
var scrollWidth = div.offsetWidth - div.clientWidth; | |
document.body.removeChild(div); | |
return scrollWidth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment