JSとCSSを読み込みます
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link rel="stylesheet" href="slick/slick.css" type="text/css" media="all" />
<script type="text/javascript" src="slick/slick.js"></script>
<script type="text/javascript" src="js/main.js"></script>
main.js JavaScript
$(function() {
//slick
$(".slider-for01").slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
//arrows: false,
fade: true,
adaptiveHeight: true,
asNavFor: '.slider-nav01'
});
$(".slider-nav01").slick({
slidesToShow: 8,
slidesToScroll: 1,
asNavFor: '.slider-for01',
//centerMode: true,
focusOnSelect: true
});
$(".slider-for02").slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
//arrows: false,
fade: true,
adaptiveHeight: true,
asNavFor: '.slider-nav02'
});
$(".slider-nav02").slick({
slidesToShow: 8,
slidesToScroll: 1,
asNavFor: '.slider-for02',
//centerMode: true,
focusOnSelect: true
});
$(".slider-for03").slick({
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
//arrows: false,
fade: true,
adaptiveHeight: true,
asNavFor: '.slider-nav03'
});
$(".slider-nav03").slick({
slidesToShow: 8,
slidesToScroll: 1,
asNavFor: '.slider-for03',
//centerMode: true,
focusOnSelect: true
});
//枚数がカルーセルに満たない場合
$(function() {
$(".mod_slide").each(function() {
var slidepak = $(this);
var image = $(slidepak).find(".mod_slide_img");
var num = $(slidepak).find(".mod_slide_img img").length;
var dots = $(slidepak).find(".slick-dots li");
var navimglast = $(slidepak).find("div.mod_slide_nav div.slick-track>div.slick-slide:last-child");
var prevbtn = $(slidepak).find("button.slick-prev");
var nextbtn = $(slidepak).find("button.slick-next");
var slidernav = $(slidepak).find(".mod_slide_nav .slick-track>div");
//
if (num < 8) {
$(dots).click(function() {
$(slidernav).removeClass("slick-current");
var indexnum = $(dots).index(this) + 1;
var checkimg = $(slidepak).find(".mod_slide_nav .slick-track>div:nth-child(" + indexnum + ")");
$(checkimg).addClass("slick-current");
});
function currmove() {
$(slidernav).removeClass("slick-current");
var curr = $(slidepak).find(".slick-dots li.slick-active");
var currIndex = $(dots).index(curr) + 1;
var btncheckimg = $(slidepak).find(".mod_slide_nav .slick-track>div:nth-child(" + currIndex + ")");
$(btncheckimg).addClass("slick-current");
}
$(prevbtn).click(function() {
currmove();
});
$(nextbtn).click(function() {
currmove();
});
// On swipe event
$(image).on('swipe', function(event, slick, direction) {
currmove();
// left
});
}
});
});
});
HTMl
<div class="mod_slide">
<div class="mod_slide_img slider-for01">
<div><img src="img/01.jpg" /></div>
<div><img src="img/02.jpg" /></div>
<div><img src="img/03.jpg" /></div>
<div><img src="img/04.jpg" /></div>
<div><img src="img/05.jpg" /></div>
<div><img src="img/06.jpg" /></div>
<div><img src="img/07.jpg" /></div>
<div><img src="img/08.jpg" /></div>
<div><img src="img/09.jpg" /></div>
</div>
<div class="mod_slide_nav slider-nav01">
<div><img src="img/01.jpg" /></div>
<div><img src="img/02.jpg" /></div>
<div><img src="img/03.jpg" /></div>
<div><img src="img/04.jpg" /></div>
<div><img src="img/05.jpg" /></div>
<div><img src="img/06.jpg" /></div>
<div><img src="img/07.jpg" /></div>
<div><img src="img/08.jpg" /></div>
<div><img src="img/09.jpg" /></div>
</div>
<!-- //mod_slide --></div>
CSS
@charset "utf-8";
/* mod_body
-----------------------------------------*/
.mod_body{
margin: 0 auto;
width: 967px;
margin-top: 50px;
}
.mod_body p{
margin: 20px 0 20px 0;
}
/* mod_slide
-----------------------------------------*/
.mod_slide{
margin:0 auto;
width:706px;
margin-bottom: 50px;
}
.mod_slide .mod_slide_nav .slick-slide{
margin:5px;
}
.mod_slide .mod_slide_nav .slick-slide img{
width:100%;
height:auto;
box-sizing:border-box;
border:solid 2px #FFF;
cursor: pointer;
}
.mod_slide .mod_slide_nav .slick-slide.slick-current img{
border:solid 2px #f5a711;
}
.slick-initialized .slick-slide {
overflow:hidden;
}
/* slick-list */
.mod_slide_nav .slick-list {
margin: 0 30px 0 30px;
}
/* slick-dots */
.slick-dots {
margin-top: 10px;
display: block;
list-style: outside none none;
padding: 0;
text-align: center;
width: 100%;
}
.slick-dots li {
cursor: pointer;
display: inline-block;
height: 20px;
margin: 0 5px;
padding: 0;
position: relative;
width: 15px;
}
.slick-dots li button {
background: transparent none repeat scroll 0 0;
border: 0 none;
color: transparent;
cursor: pointer;
display: block;
font-size: 0;
height: 20px;
line-height: 0;
outline: medium none;
padding: 5px;
width: 20px;
}
.slick-dots li button:hover, .slick-dots li button:focus {
outline: medium none;
}
.slick-dots li button:hover::before, .slick-dots li button:focus::before {
opacity: 1;
}
.slick-dots li button::before {
color: black;
content: "●";
font-size: 28px;
height: 20px;
left: 0;
line-height: 20px;
opacity: 0.25;
position: absolute;
text-align: center;
top: 0;
width: 15px;
}
.slick-dots li.slick-active button::before {
color: black;
opacity: 0.55;
font-size: 34px;
}
/* */
.slick-prev, .slick-next {
background: transparent none repeat scroll 0 0;
border: medium none;
color: transparent;
cursor: pointer;
display: block;
font-size: 0;
height: 20px;
line-height: 0;
margin-top: -30px;
outline: medium none;
padding: 0;
position: absolute;
top: 50%;
width: 20px;
z-index:9;
}
.slick-prev:hover, .slick-prev:focus, .slick-next:hover, .slick-next:focus {
background: transparent none repeat scroll 0 0;
color: transparent;
outline: medium none;
}
.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: 0.25;
}
.slick-prev::before, .slick-next::before {
color: #666;
font-size: 20px;
line-height: 1;
opacity: 0.75;
}
.slick-prev {
left: 0px;
}
[dir="rtl"] .slick-prev {
left: auto;
right: 0px;
}
.slick-prev::before {
content: " \f053";
font-family: FontAwesome;
}
[dir="rtl"] .slick-prev::before {
content: " \f054";
font-family: FontAwesome;
}
.slick-next {
right: 0px;
}
[dir="rtl"] .slick-next {
left: 0px;
right: auto;
}
.slick-next::before {
content: " \f054";
font-family: FontAwesome;
}
[dir="rtl"] .slick-next::before {
content: " \f053";
font-family: FontAwesome;
}