0
,我有以下的jQuery代碼媒體查詢:包括在JavaScript
jQuery('.slider-home').slick({
slidesToShow: 4,
slidesToScroll: 1,
asNavFor: '.slider-for, .slider-arrow',
focusOnSelect: true,
autoplay: false,
arrows: true
});
我想,這樣的slidesToShow從1移動變爲4在桌面上添加一個媒體查詢。
我曾嘗試下面的代碼:
if (matchMedia('only screen and (max-width: 1024px)').matches) {
jQuery('.slider-home').slick({
slidesToShow: 1
});
} else {
jQuery('.slider-home').slick({
slidesToShow: 4
});
但它似乎沒有工作,沒有任何機構有任何想法,我要去的地方錯了嗎?
爲什麼不只是使用CSS來隱藏它? – KeepMove