一、首先要引入swiper.min.css和swiper.min.js两个库;
二、接着在在最外层标签内部加入swiper-container类,在内层加入swiper-wrapper类,在图片标签上加入swiper-slide类,如下所示 :
<div class="swiper-container">
<div class="swiper-wrapper">
<img class="swiper-slide " src="img/logo1.jpg " />
</div>
三、在js中加入以下代码块,另外查看swiper库,找到对应的功能按需求把自己需要的部分添加到js中或者Html中,实现所需要的功能;
var mySwiper = new Swiper('.swiper-container',{
loop: true,
autoplay: 3000,
});
四、具体的参考例子如下所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Swiper中文网基础演示(www.swiper.com.cn)</title>
<link rel="stylesheet" href="css/swiper.min.css">
<!--Swiper3.0.4-->
<style>
* {
margin: 0;
padding: 0;
}
.blue-slide {
background: #4390EE;
}
.red-slide {
background: #CA4040;
}
.orange-slide {
background: #FF8604;
}
.swiper-slide {
line-height: 300px;
color: #fff;
font-size: 36px;
text-align: center;
}
</style>
</head>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<img class="swiper-slide " src="img/logo1.jpg " />
<img class="swiper-slide " src="img/logo2.jpg " />
<img class="swiper-slide " src="img/logo3.jpg " />
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<script src="js/swiper.min.js"></script>
<script type="text/javascript">
var mySwiper = new Swiper('.swiper-container',{
loop: true,
autoplay: 3000,
// 如果需要分页器
pagination : '.swiper-pagination',
// 如果需要前进后退按钮
prevButton:'.swiper-button-prev',
nextButton:'.swiper-button-next',
//切换速度,值越大速度越慢
//speed:800,
});
</script>
</body>
</html>