我正在使用淡化滑块我想一次显示一个图像,但我的滑块无效:
<head>
<link href="js/slick-theme.css" rel="stylesheet" type="text/css" />
<link href="js/slick.css" rel="stylesheet" type="text/css" />
<script src="js/slick.js" type="text/javascript"></script>
<script src="js/slick.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('.fade').slick({
dots: true,
infinite: true,
speed: 500,
fade: true,
cssEase: 'linear'
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="fade">
<div>
<img src="images/ProductName/6.jpg" alt="" />
<img src="images/ProductName/6.jpg" alt="" />
</div>
</div>
</form>
</body>
上面的代码正在显示图像,但滑块没有应用。我希望图像逐个显示,但它不能正常工作
答案 0 :(得分:1)
您需要添加Jquery库。 “”。试试这个。
$(document).on('ready', function() {
$(".regular").slick({
dots: true,
infinite: true,
slidesToShow: 3,
slidesToScroll: 3
});
$(".center").slick({
dots: true,
infinite: true,
centerMode: true,
slidesToShow: 3,
slidesToScroll: 3
});
$(".variable").slick({
dots: true,
infinite: true,
variableWidth: true
});
});
html, body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
.slider {
width: 50%;
margin: 100px auto;
}
.slick-slide {
margin: 0px 20px;
}
.slick-slide img {
width: 100%;
}
.slick-prev:before,
.slick-next:before {
color: black;
}
<!DOCTYPE html>
<html>
<head>
<title>Slick Playground</title>
<meta charset="UTF-8">
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css" rel="stylesheet"/>
</head>
<body>
<section class="regular slider">
<div>
<img src="http://placehold.it/350x300?text=1">
</div>
<div>
<img src="http://placehold.it/350x300?text=2">
</div>
<div>
<img src="http://placehold.it/350x300?text=3">
</div>
<div>
<img src="http://placehold.it/350x300?text=4">
</div>
<div>
<img src="http://placehold.it/350x300?text=5">
</div>
<div>
<img src="http://placehold.it/350x300?text=6">
</div>
</section>
<section class="center slider">
<div>
<img src="http://placehold.it/350x300?text=1">
</div>
<div>
<img src="http://placehold.it/350x300?text=2">
</div>
<div>
<img src="http://placehold.it/350x300?text=3">
</div>
<div>
<img src="http://placehold.it/350x300?text=4">
</div>
<div>
<img src="http://placehold.it/350x300?text=5">
</div>
<div>
<img src="http://placehold.it/350x300?text=6">
</div>
<div>
<img src="http://placehold.it/350x300?text=7">
</div>
<div>
<img src="http://placehold.it/350x300?text=8">
</div>
<div>
<img src="http://placehold.it/350x300?text=9">
</div>
</section>
<section class="variable slider">
<div>
<img src="http://placehold.it/350x300?text=1">
</div>
<div>
<img src="http://placehold.it/200x300?text=2">
</div>
<div>
<img src="http://placehold.it/100x300?text=3">
</div>
<div>
<img src="http://placehold.it/200x300?text=4">
</div>
<div>
<img src="http://placehold.it/350x300?text=5">
</div>
<div>
<img src="http://placehold.it/300x300?text=6">
</div>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.js"></script>
</body>
答案 1 :(得分:1)
首先,您必须添加jquery,然后移除包含两个图像的div
,这就是它同时显示图片的原因,同时为您的脚本添加$.ready
功能以确保dom loading。
这是Fiddle
$( document ).ready(function(){
$('.fade').slick({
dots: true,
infinite: true,
speed: 500,
fade: true,
cssEase: 'linear'
});
})
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick-theme.css" rel="stylesheet"/>
<link href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css" rel="stylesheet"/>
<script src="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.min.js"></script>
<div style="background-color:gray">
<form id="form1" runat="server">
<div class="fade" style="width:40%;margin:auto">
<img src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" alt="" />
<img src="http://www.jqueryscript.net/images/Cross-browser-Image-Carousel-Plugin-For-jQuery-carouselOnPC.jpg" alt="" />
</div>
</form>
</div>