Slick carousel moving nav dots

混江龙づ霸主 提交于 2019-12-23 02:41:10

问题


I am using http://kenwheeler.github.io/slick carousel and I need to limit dots number to 8 even if there more than 8 slides.

Nav dots should have arrows to the left and to the right that suggest user that there are more dots to show.

Can anybody suggest a solution / had similar experience in customizing nav dots with slick?


回答1:


I came up with a solution to limit the number of dots to three using CSS

/* hiding all bullets by default */
.slick-dots li {
    display: none
}
/* only displaying the active bullets and the 2 bullets next to it */
.slick-dots li.slick-active,
.slick-dots li.slick-active + li,
.slick-dots li.slick-active + li + li {
    display: block;
}
/* displaying the last three bullets when slick-active class isn't applied to any li before them  */
.slick-dots li:nth-last-child(1),
.slick-dots li:nth-last-child(2),
.slick-dots li:nth-last-child(3) {
    display: block;
}
/* hiding the last three bullets if slick-active exist before them */
.slick-dots li.slick-active ~ li:nth-last-child(1),
.slick-dots li.slick-active ~ li:nth-last-child(2),
.slick-dots li.slick-active ~ li:nth-last-child(3) {
    display: none;
}
/* specific conditions to always display the last three bullets */
.slick-dots li.slick-active + li + li:nth-last-child(3),
.slick-dots li.slick-active + li + li:nth-last-child(2),
.slick-dots li.slick-active + li + li:nth-last-child(1),
.slick-dots li.slick-active + li:nth-last-child(3),
.slick-dots li.slick-active + li:nth-last-child(2),
.slick-dots li.slick-active + li:nth-last-child(1){
    display: block;
}

Of course this can be made pretty with preprocessors but it is working.

Working fiddle: http://jsfiddle.net/1gLn1cbg/




回答2:


I recently developed something like this, you can restrict this to as many dots as you like. I have done it for 5 dots, after that additional dots are not shown, but scroll when your main slides scroll.

You can use the init and change events to accomplish this.

slickSlider.on('init', function (event, slick) {

slickSlider.on('beforeChange', function (event, slick) {

Working example: https://codepen.io/swarad07/pen/xmzQKm

This is very similar to how Instagram does it, with edge dots smaller in size.



来源:https://stackoverflow.com/questions/33122912/slick-carousel-moving-nav-dots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!