Skip to content

Instantly share code, notes, and snippets.

@Dziuperman
Last active May 2, 2019 07:04
Show Gist options
  • Save Dziuperman/a7c76c78d9dc5d14d91c796d81b4d6ff to your computer and use it in GitHub Desktop.
Save Dziuperman/a7c76c78d9dc5d14d91c796d81b4d6ff to your computer and use it in GitHub Desktop.
Вызов нескольких slick слайдеров при клике на превью
let documentsSlider = document.querySelectorAll('.documents-slider');
let documentsPrevItem = document.querySelectorAll('.documents-prev__item');
let close = document.querySelectorAll('.close');
let jsSl = document.querySelectorAll('.js-sl');
var sliderRefresh = false;
jQuery(document).ready(function() {
$(documentsSlider).hide();
$(documentsPrevItem).on('click', function() {
$(this).children(documentsSlider).css("display", "flex");
$('body').css("overflow", "hidden");
$(this).find(jsSl).each(function() {
let showSlides = 3;
let countSlides = $(this).find('.sl__slide').length;
if (countSlides < showSlides) {
showSlides = 1;
}
// if (showSlides = 1) {
// $(this).closest('.documents-slider__content').each(function(item) {
// $(this).css("width", "60%");
// });
// $(this).find('.sl__img>img').each(function() {
// $(this).css({"width": "100%", "max-width": ""});
// });
// }
$(this).not('.slick-initialized').slick({
centerMode: true,
centerPadding: "0px",
dots: true,
dotsClass: 'documents-slider__dots',
focusOnSelect: true,
slidesToShow: showSlides,
slidesToScroll: 1,
// cssEase: 'ease-out',
// variableWidth: true,
prevArrow: $(this).parent('.documents-slider__content').find('.slider-nav--prev'),
nextArrow: $(this).parent('.documents-slider__content').find('.slider-nav--next'),
responsive: [
{
breakpoint: 769,
settings: {
slidesToShow: 1
}
},
]
});
// refresh slider
if(!sliderRefresh) {
$(this).slick('refresh');
sliderRefresh = true;
};
});
$('body').on('click', '.close', function() {
$('body').css("overflow", "");
$(documentsSlider).hide();
sliderRefresh = false;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment