**sweiper官方网址:https://www.swiper.com.cn/**(API有关于组件的用法的描述)
下面的例子为精选的轮播
~~~
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/css/swiper.min.css">
<style>
.swiper-container {
//可对大小进行定制设定
}
.swiper-pagination-bullet{
//对下面的小圆点进行定制设定
}
.swiper-pagination-bullet-active{
//对小圆点的背景颜色进行定制设定
}
</style>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><img src="快选择照片放这里吧" alt=""></div>
<div class="swiper-slide"><img src="快选择照片放这里吧" alt=""></div>
<div class="swiper-slide"><img src="快选择照片放这里吧" alt=""></div>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/js/swiper.min.js"></script>
<script>
var mySwiper = new Swiper ('.swiper-container', {
loop: true,
//autoplay设置自动切换
autoplay: {
delay: 2000,
stopOnLastSlide: false,
disableOnInteraction: true,
},
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
},
// 如果需要前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
})
</script>
~~~
又一个轮播
~~~
<div class="container">
<div id="list" style="left: 0px;">
<img src="这里添加图片" alt="">
<img src="这里添加图片" alt="">
<img src="这里添加图片" alt="">
<img src="这里添加图片" alt="">
<img src="这里添加图片" alt="">
</div>
<button id="prev"></button>
<button id="next"></button>
<div id="btns">
<span class="current"></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<script>
var list = document.getElementById("list");
var prev = document.getElementById("prev");
var next = document.getElementById("next");
var btns= document.getElementById("btns").children;
var index = 0;
prev.onclick = function(){
animate(600);
xiaoyuandian(-1);
}
next.onclick = function(){
animate(-600);
xiaoyuandian(1);
}
function xiaoyuandian(k){
index+=k;
if(index>4){
index = 0;
}else if(index<0){
index = 4;
}
for(var j=0;j<btns.length;j++){
btns[j].classList.remove("current")
}
btns[index].classList.add("current");
}
function animate(offset){
let newleft = parseInt(list.style.left) + offset;
if(newleft<-2400){
newleft = 0;
}else if (newleft>0){
newleft = -2400;
}
list.style.left = newleft + "px";
}
for(var i=0;i<btns.length;i++){
btns[i].index = i;
btns[i].onclick = function(){
for(var j=0;j<btns.length;j++){
btns[j].classList.remove("current");
}
var newset = (this.index-index)*(-600);
console.log(newset);
animate(newset);
index = this.index;
this.classList.add("current");
}
}
</script>
~~~