Answer the question
In order to leave comments, you need to log in
How to correctly connect Slick Slider in a modal window?
How to correctly connect Slick Slider in a modal window in jQuery code? Tried:
$('.portfolio__btn_1').on('click', function() {
$('.portfolio__popup_1').fadeIn(200)
$('body').addClass('no-scroll')
let arrowsTop
if ($(window).width() <= '560') { // Адаптация стрелок под мобильные устройства.
arrowsTop = true // Если ширина экрана больше 560 пикселей, то стрелки переключения появляются.
} else {
arrowsTop = false // Если нет, то убираются.
}
$(window).resize(function() {
if ($(window).width() <= '560') { // Тоже самое, что и сверху, только при изменении ширины экрана.
arrowsTop = true
} else {
arrowsTop = false
}
})
$('.popup__slider').slick({ // Подключение Slick Slider
slidesToShow: 1,
slidesToScroll: 1,
arrows: arrowsTop,
fade: true,
asNavFor: '.popup__slider_nav'
});
$('.popup__slider_nav').slick({
slidesToShow: 3,
slidesToScroll: 1,
asNavFor: '.popup__slider',
centerMode: true,
arrows: true,
focusOnSelect: true
});
})
})
Answer the question
In order to leave comments, you need to log in
- you need to initialize the slider once, not on every call
- You can collect on each call so that the slider recalculates the position and shows correctly $(".slider").slick('setPosition');
- Disabling the arrows must be done through the breakpoints of the slick itself:
$('.popup__slider').slick({ // Подключение Slick Slider
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
asNavFor: '.popup__slider_nav',
responsive: [
{
breakpoint: 560,
settings: {
arrows: true
}
}
]
});
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question