Last active
June 9, 2016 13:08
-
-
Save michalvalasek/e570c3da74351292739b577ac4c970f2 to your computer and use it in GitHub Desktop.
Adaptive Slick Slider
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
<!-- put mobile (smaller) images URIs to the data-images attribute, separate them by semicolon --> | |
<div id="slider-mobile" class="slick-slider" data-images="http://dummyimage.com/300x200/000/00f;http://dummyimage.com/300x200/000/f00;http://dummyimage.com/300x200/000/0f0"> | |
</div> | |
<!-- put desktop (larger) images URIs to the data-images attribute, separate them by semicolon --> | |
<div id="slider-desktop" class="slick-slider" data-images="http://dummyimage.com/600x400/000/00f;http://dummyimage.com/600x400/000/f00;http://dummyimage.com/600x400/000/0f0"> | |
</div> |
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
// main js file | |
// the init_slick_slider.js needs to be loaded at this point | |
$(function(){ | |
// initialize the right slick slider when document is ready | |
$('.slick-slider').initSlickSlider(); | |
}); |
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
// mini jQuery plugin that initializes the Slick plugin on one of the sliders (the one that is visible) | |
// you can pass object with config options for Slick | |
$.fn.initSlickSlider = function(slickOpts) { | |
slickOpts = $.extend({ | |
autoplay: true, | |
arrows: false, | |
pauseOnHover: false, | |
infinite: true, | |
speed: 500, | |
fade: true, | |
cssEase: 'linear' | |
}, slickOpts); | |
this.each(function(){ | |
var $slider = $(this); | |
if ( $slider.is(':visible') ) { | |
$slider.data('images').split(';').forEach(function(url){ | |
$slider.append('<img src="'+url+'" />'); | |
}); | |
$slider.slick(slickOpts); | |
} | |
}) | |
} |
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
.slick-slider img { | |
height: auto; | |
} | |
/* show only the #slider-mobile on small screens */ | |
@media (max-width: 767px) { | |
#slider-mobile { | |
display: block; | |
} | |
#slider-desktop { | |
display: none; | |
} | |
} | |
/* show only the #slider-desktop on big screens */ | |
@media (min-width: 768px) { | |
#slider-mobile { | |
display: none; | |
} | |
#slider-desktop { | |
display: block; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment