我正在使用Slick轮播,并希望显示3张照片。我在底部的导航栏窗格中显示了3张照片。如果我设置slidesToShow = 2,一切都会按预期进行,但是当slidesToShow = 3(等于幻灯片的总数)时,幻灯片会在底部导航中显示2个空白幻灯片,即使它在顶部滑块中仅正确显示了3个主要幻灯片,用于窗格。
我意识到,如果我将autoplay = false设为true,那么它将按预期工作,但是我在显示想要自动循环的照片之前/期间/之后,因此客户可以在导航幻灯片中看到所有可能的选择自动播放。
任何想法如何使它起作用?我已经看到有人提到不应这样做,但这似乎是一个有价值的用例。至少在我的情况下。我很感激!
$('.slider-for').slick({
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 4000,
arrows: true,
fade: true,
asNavFor: '.slider-nav' /* the child Nav bar */
});
$('.slider-nav').slick({ /* the Nav display with thumbnails */
slidesToShow: 3,
slidesToScroll: 1,
asNavFor: '.slider-for', /* the parent slider */
dots: false,
focusOnSelect: true,
arrows: false,
infinite: true
});
.main {
font-family:Arial;
width:500px;
display:block;
margin:0 auto;
}
.description {
background: #fff;
color: black;
font-size: 20px;
margin: 10px;
padding: 2%;
position: relative;
text-align: center;
}
.main h3 {
background: #fff;
color: black;
font-size: 20px;
line-height: 100px;
margin: 10px;
padding: 2%;
position: relative;
text-align: center;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="slick/slicktheme.css"/>
</head>
<body>
<header>
</header>
<main>
<section class="main" align="center">
<div class="slider slider-for">
<div>
<img src="images/Siding/ChimneyRottingHoles.jpg"alt="Chimney with Hardboard Siding Rotting with holes">
</div>
<div>
<img src="images/Siding/Chimney New Flashing.jpg"
alt="Chimney replaced with new hardboard siding, new flashing and new cedar trim boards">
</div>
<div>
<img src="images/Siding/Chimney Cedar New Paint.jpg"
alt="Chimney and cedar trim repainted with Sherwin Williams Exterior Super Paint in a Satin finish">
</div>
</div>
<div class="slider slider-nav">
<div class="description">Rotted Siding with Holes
<h3 style="background-image: url('images/Siding/Chimney Rotting Holes.jpg'); background-size: cover">
</h3>
</div>
<div class="description">New Siding & Flashing
<h3 style="background-image: url('images/Siding/Chimney New Flashing.jpg'); background-size: cover">
</h3>
</div>
<div class="description">Painted in Satin Finish
<h3 style="background-image: url('images/Siding/Chimney Cedar New Paint.jpg'); background-size: cover">
</h3>
</div>
</div>
</section>
</main>
<footer>
</footer>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="slick/slick.min.js"></script>
<script>
$('.slider-for').slick({
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 4000,
arrows: true,
fade: true,
asNavFor: '.slider-nav' /* the child Nav bar */
});
$('.slider-nav').slick({
/* the Nav display with thumbnails */ slidesToShow: 3,
slidesToScroll: 1,
asNavFor: '.slider-for', /* the parent slider */
dots: false,
focusOnSelect: true,
arrows: false,
infinite: true
});
</script>
</body>
</html>
答案 0 :(得分:-2)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js">
</script>
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css"/>
<style>
.main {
font-family:Arial;
width:500px;
display:block;
margin:0 auto;
}
.description {
background: #fff;
color: black;
font-size: 20px;
margin: 10px;
padding: 2%;
position: relative;
text-align: center;
}
.main h3 {
background: #fff;
color: black;
font-size: 20px;
line-height: 100px;
margin: 10px;
padding: 2%;
position: relative;
text-align: center;
}
body {
background-color: #dfdfdf;
}
</style>
</head>
<body>
<main>
<section class="main" align="center">
<div class="slider slider-for">
<div><img src="images/Siding/Chimney Rotting Holes.jpg" alt="Chimney with Hardboard Siding Rotting with holes"></div>
<div><img src="images/Siding/Chimney New Flashing.jpg" alt="Chimney replaced with new hardboard siding, new flashing and new cedar trim boards"></div>
<div><img src="images/Siding/Chimney Cedar New Paint.jpg" alt="Chimney and cedar trim repainted with Sherwin Williams Exterior Super Paint in a Satin finish"></div>
</div>
<div class="slider slider-nav">
<div class="description">Rotted Siding with Holes<h3 style="background-image: url('images/Siding/Chimney Rotting Holes.jpg'); background-size: cover"> </h3></div>
<div class="description">New Siding & Flashing<h3 style="background-image: url('images/Siding/Chimney New Flashing.jpg'); background-size: cover"> </h3></div>
<div class="description">Painted in Satin Finish<h3 style="background-image: url('images/Siding/Chimney Cedar New Paint.jpg'); background-size: cover"> </h3></div>
</div>
</section>
</main>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js"></script>
<script>
$('.slider-for').slick({
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 4000,
arrows: true,
fade: true,
asNavFor: '.slider-nav' /* the child Nav bar */
});
$('.slider-nav').slick({ /* the Nav display with thumbnails */
slidesToShow: 2,
slidesToScroll: 1,
asNavFor: '.slider-for', /* the parent slider */
dots: false,
focusOnSelect: true,
arrows: false,
infinite: true
});
</script>
</div>
</body>
</html>