如何从“滑动滑块同步”中删除滑块导航并显示缩略图?
Posted
技术标签:
【中文标题】如何从“滑动滑块同步”中删除滑块导航并显示缩略图?【英文标题】:How to remove slider nav from 'Slick slider syncing' and show thumbnails instead? 【发布时间】:2018-10-17 06:09:23 【问题描述】:我正在使用Slick slider syncing 通过单击其下方滑块导航中的缩略图来显示图像。附上工作代码sn-p。
如果你运行 sn -p,你会看到有两个滑块:
-
顶部的第一个以大尺寸显示图像
第二个显示像缩略图一样的幻灯片,单击每个图像将在第一个滑块上显示相同的图像。
我想在缩略图中显示图像,而不是第二个滑块,如下图所示,并且仍然希望它以相同的方式工作,即每当我单击缩略图中的任何图像时,它应该在第一个滑块中显示相同的图像。
有人可以帮帮我吗?不知道如何让它工作。
$(document).ready(function()
$('.slider-for').slick(
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
asNavFor: '.slider-nav'
);
$('.slider-nav').slick(
slidesToShow: 3,
slidesToScroll: 1,
asNavFor: '.slider-for',
dots: true,
centerMode: true,
focusOnSelect: true
);
);
/* Slider */
.slick-slider
position: relative;
display: block;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-khtml-user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
.slick-list
position: relative;
display: block;
overflow: hidden;
margin: 0;
padding: 0;
.slick-list:focus
outline: none;
.slick-list.dragging
cursor: pointer;
cursor: hand;
.slick-slider .slick-track,
.slick-slider .slick-list
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.slick-track
position: relative;
top: 0;
left: 0;
display: block;
.slick-track:before,
.slick-track:after
display: table;
content: '';
.slick-track:after
clear: both;
.slick-loading .slick-track
visibility: hidden;
.slick-slide
display: none;
float: left;
height: 100%;
min-height: 1px;
[dir='rtl'] .slick-slide
float: right;
.slick-slide img
display: block;
.slick-slide.slick-loading img
display: none;
.slick-slide.dragging img
pointer-events: none;
.slick-initialized .slick-slide
display: block;
.slick-loading .slick-slide
visibility: hidden;
.slick-vertical .slick-slide
display: block;
height: auto;
border: 1px solid transparent;
.slick-arrow.slick-hidden
display: none;
@charset 'UTF-8';
/* Slider */
.slick-loading .slick-list
background: #fff url('./ajax-loader.gif') center center no-repeat;
/* Icons */
@font-face
font-family: 'slick';
font-weight: normal;
font-style: normal;
src: url('./fonts/slick.eot');
src: url('./fonts/slick.eot?#iefix') format('embedded-opentype'), url('./fonts/slick.woff') format('woff'), url('./fonts/slick.ttf') format('truetype'), url('./fonts/slick.svg#slick') format('svg');
/* Arrows */
.slick-prev,
.slick-next
font-size: 0;
line-height: 0;
position: absolute;
top: 50%;
display: block;
width: 20px;
height: 20px;
padding: 0;
margin-top: -10px\9; /*lte IE 8*/
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
transform: translate(0, -50%);
cursor: pointer;
color: transparent;
border: none;
outline: none;
background: transparent;
.slick-prev:hover,
.slick-prev:focus,
.slick-next:hover,
.slick-next:focus
color: transparent;
outline: none;
background: transparent;
.slick-prev:hover:before,
.slick-prev:focus:before,
.slick-next:hover:before,
.slick-next:focus:before
opacity: 1;
.slick-prev.slick-disabled:before,
.slick-next.slick-disabled:before
opacity: .25;
.slick-prev:before,
.slick-next:before
font-family: 'slick';
font-size: 20px;
line-height: 1;
opacity: .75;
color: white;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
.slick-prev
left: -25px;
[dir='rtl'] .slick-prev
right: -25px;
left: auto;
.slick-prev:before
content: '←';
[dir='rtl'] .slick-prev:before
content: '→';
.slick-next
right: -25px;
[dir='rtl'] .slick-next
right: auto;
left: -25px;
.slick-next:before
content: '→';
[dir='rtl'] .slick-next:before
content: '←';
/* Dots */
.slick-slider
margin-bottom: 30px;
.slick-dots
position: absolute;
bottom: -45px;
display: block;
width: 100%;
padding: 0;
list-style: none;
text-align: center;
.slick-dots li
position: relative;
display: inline-block;
width: 20px;
height: 20px;
margin: 0 0px;
padding: 0;
cursor: pointer;
.slick-dots li button
font-size: 0;
line-height: 0;
display: block;
width: 20px;
height: 20px;
padding: 5px;
cursor: pointer;
color: transparent;
border: 0;
outline: none;
background: transparent;
.slick-dots li button:hover,
.slick-dots li button:focus
outline: none;
.slick-dots li button:hover:before,
.slick-dots li button:focus:before
opacity: 1;
.slick-dots li button:before
font-family: 'slick';
font-size: 8px;
line-height: 20px;
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
content: '•';
text-align: center;
opacity: .8;
color: #ffb608;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
.slick-dots li.slick-active button:before
opacity: 1;
font-size:12px;
color: #ffb608;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.pic
width: 200px;
height: 200px;
background-color: lightgrey;
border: grey;
.pink background-color: pink;
.orange background-color: orange;
.green background-color: lightgreen;
</style>
</head>
<body>
<div class="slider-for">
<div class="pink pic">1</div>
<div class="orange pic">2</div>
<div class="green pic">3</div>
<div class="orange pic">4</div>
<div class="pink pic">5</div>
<div class="green pic">6</div>
<div class="pink pic">7</div>
<div class="green pic">8</div>
<div class="orange pic">9</div>
</div>
<div class="slider-nav">
<div class="pink pic">1</div>
<div class="orange pic">2</div>
<div class="green pic">3</div>
<div class="orange pic">4</div>
<div class="pink pic">5</div>
<div class="green pic">6</div>
<div class="pink pic">7</div>
<div class="green pic">8</div>
<div class="orange pic">9</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
</body>
</html>
【问题讨论】:
使用 slickGoTo() 导航到幻灯片 【参考方案1】:这是一个演示,现在根据您的需要更改 css
https://codepen.io/anon/pen/YLExGd
$(document).ready(function()
$(".slideshow").slick(
dots: true
);
$(".menu a").click(function(e)
e.preventDefault();
slideIndex = $(this).index();
$( '.slideshow' ).slickGoTo( parseInt(slideIndex) );
);
);
a img width:100px
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.3.6/slick.css"/>
<style>
.menu
text-align: center;
.container
width: 400px;
margin:1em auto;
.slick-prev:before, .slick-next:before
color: gray ! important;
</style>
</head>
<body>
<div class="menu">
<a href="#"><img src="https://lorempixel.com/400/200/nature/IMAGE-01/"></a>
<a href="#"><img src="https://lorempixel.com/400/200/nature/IMAGE-02/"></a>
<a href="#"><img src="https://lorempixel.com/400/200/nature/IMAGE-03/"></a>
<a href="#"><img src="https://lorempixel.com/400/200/nature/IMAGE-04/"></a>
<a href="#"><img src="https://lorempixel.com/400/200/nature/IMAGE-05/"></a>
</div>
<div class="container">
<div class="slideshow">
<div><img src="https://lorempixel.com/400/200/nature/IMAGE-01/"></div>
<div><img src="https://lorempixel.com/400/200/nature/IMAGE-02/"></div>
<div><img src="https://lorempixel.com/400/200/nature/IMAGE-03/"></div>
<div><img src="https://lorempixel.com/400/200/nature/IMAGE-04/"></div>
<div><img src="https://lorempixel.com/400/200/nature/IMAGE-05/"></div>
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.slick/1.3.6/slick.min.js"/></script>
</body>
</html>
【讨论】:
以上是关于如何从“滑动滑块同步”中删除滑块导航并显示缩略图?的主要内容,如果未能解决你的问题,请参考以下文章