swiper插件用于做各种动画如轮播图,滑动菜单等等,通过swiper可以快速的得到我们想要的动画效果 官网地址:https://www.swiper.com.cn/
使用方法
选择需要的版本
点击在线演示
选择一个喜欢的特效记住编号
随后在下载的文件 demos即可看到对应的编号demo
查看其结构源代码然后应用到自己的项目
示例swiper做轮播图
1.引入基础文件
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/swiper-bundle.css">
</head>
<body>
<script type="text/javascript" src="js/swiper-bundle.js"></script>
</body>
</html>
2.复制demo的html结构我使用的是30
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
<div class="swiper-slide">Slide 10</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
3.替换结构
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/swiper-bundle.css">
</head>
<body>
<div class="main">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src='img/one.jpg'>
</div>
<div class="swiper-slide">
<img src="img/two.jpg">
</div>
<div class="swiper-slide">
<img src="img/three.jpg">
</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
<script type="text/javascript" src="js/swiper-bundle.js"></script>
</body>
</html>
4.复制样式和定义自己的样式
html,
body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
/*自定义样式*/
.main{
width: 300px;
height: 100px;
margin:0 auto;
}
img{
width: 100%;
}
5.根据文档或demo添加js代码
<script type="text/javascript">
var swiper = new Swiper('.swiper-container', {
autoplay:true,
pagination: {
el: '.swiper-pagination'
},
});
</script>
最终效果
与他相似的插件还有 superslide http://www.superslide2.com/
iscroll http://github.com/cubiq/iscroll