gpt4 book ai didi

javascript - 可以根据浏览器大小使 slider 响应吗?

转载 作者:行者123 更新时间:2023-11-28 08:15:08 24 4
gpt4 key购买 nike

Jsfiddle DEMO

HTML

    <section class="wrap row">
<div class="container">
<div class="slider">
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2 ">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2 ">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
<div class="col-xs-4 col-sm-4 col-lg-2">
<img src="http://www.clker.com/cliparts/f/5/6/f/1352194206656819167small_ragdoll_kitten-md.png" />
</div>
</div>
</div>
</section>

JQuery

$('.slider').slick({
centerMode: true,
centerPadding: '60px',
slidesToShow: 9,
adaptiveHeight: true,
responsive: [
{
breakpoint: 768,
settings: {
arrows: false,
centerMode: true,
centerPadding: '40px',
slidesToShow: 3
}
},
{
breakpoint: 480,
settings: {
arrows: false,
centerMode: true,
centerPadding: '40px',
slidesToShow: 2
}
}
]
});

slickjs 按预期工作,但我找不到在笔记本电脑和台式机尺寸中禁用 slick 的方法。如何在笔记本电脑和台式机尺寸下禁用 slick?

此外,在移动尺寸时,如何启用 slick 并在每张幻灯片的 2 行中显示 9 个缩略图(9 x 2 幻灯片)(不是一个幻灯片行包含所有 18 个缩略图)?认为增加高度会有帮助,但显然没有。

感谢帮助。

最佳答案

您可以使用 enquire.js对于更高级的响应位,您可以在其中记忆起您的 slickJS带有您想要的选项的轮播:

enquire.register("(max-width: 768px)", {

match : function() {
$('.slider').slick({ /* your options for smaller screens than 768px */ });
},


unmatch : function() {
$('.slider').slick({ /* your options for bigger screens than 768px */ });
}

});

在本例中,您会想起移动设备上的 slider ,其max-width768px。你必须输入你的选项,你想要多少张幻灯片,例如:

$('.slider').slick({
slidesToShow: 4,
slidesToScroll: 4
});

希望这对您有所帮助!

关于javascript - 可以根据浏览器大小使 slider 响应吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com