swiper的使用教程

今天要分享的是swiper这个插件的使用,什么是swiper呢?

Swiper常用于移动端网站的内容触摸滑动;
Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。

初学者使用swiper的时候,可以在官网(http://www.swiper.com.cn/)学,但是一开始的时候,建议不要直接看它的API文档。可以在先下载swiper,选择swiper-3.4.2完整压缩包下载,然后可以看它里面demos中的效果,你需要哪个效果,就用哪个!

使用方法(以其中demos中第21个效果为例):

1、引用JS和css文件

[html] view plaincopy
  1. <link rel="stylesheet" href="path/to/swiper.min.css">
  2. <script src="path/to/swiper.min.js"></script>

2、在body中加入以下格式的HTML格式

[html] view plaincopy
  1. <div class="swiper-container">
  2. <div class="swiper-wrapper">
  3. <div class="swiper-slide">Slide 1</div>
  4. <div class="swiper-slide">Slide 2</div>
  5. <div class="swiper-slide">Slide 3</div>
  6. </div>
  7. <!-- 如果需要分页器 -->
  8. <div class="swiper-pagination"></div>
  9. <!-- 如果需要导航按钮 -->
  10. <div class="swiper-button-prev"></div>
  11. <div class="swiper-button-next"></div>
  12. <!-- 如果需要滚动条 -->
  13. <div class="swiper-scrollbar"></div>
  14. </div>
  15. 导航等组件可以放在container之外

3、在script中加入以下js代码

[html] view plaincopy
  1. <script>
  2. var swiper = new Swiper('.swiper-container', {
  3. pagination: '.swiper-pagination',
  4. nextButton: '.swiper-button-next',
  5. prevButton: '.swiper-button-prev',
  6. paginationClickable: true,
  7. spaceBetween: 30,
  8. centeredSlides: true,
  9. autoplay: 2500,
  10. autoplayDisableOnInteraction: false
  11. });
  12. </script>

4、在head中加入css样式

[html] view plaincopy
  1. <style>
  2. html, body {
  3. position: relative;
  4. height: 100%;
  5. }
  6. body {
  7. background: #eee;
  8. font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  9. font-size: 14px;
  10. color:#000;
  11. margin: 0;
  12. padding: 0;
  13. }
  14. .swiper-container {
  15. width: 100%;
  16. height: 100%;
  17. }
  18. .swiper-slide {
  19. text-align: center;
  20. font-size: 18px;
  21. background: #fff;
  22. /* Center slide text vertically */
  23. display: -webkit-box;
  24. display: -ms-flexbox;
  25. display: -webkit-flex;
  26. display: flex;
  27. -webkit-box-pack: center;
  28. -ms-flex-pack: center;
  29. -webkit-justify-content: center;
  30. justify-content: center;
  31. -webkit-box-align: center;
  32. -ms-flex-align: center;
  33. -webkit-align-items: center;
  34. align-items: center;
  35. }
  36. </style>

至此就完成了一个简单的轮播,然后还有先script中要加的参数,我们可以在API文档中进行查阅,并添加。

注意的是:HTML中class的名字不能换,不要问为什么,就是那样用就OK了!

原创来自:http://blog.csdn.net/cq7421/article/details/77937080

swiper的使用教程相关推荐

  1. html5 swiper 菜鸟,前端插件swiper使用新手教程

    1.引入swiper.min.js和swiper.min.css两个文件,文件百度网盘下载地址链接:https://pan.baidu.com/s/1KwIzPfe9hFpSiMr5GqAWxw 提取 ...

  2. 前端插件swiper使用新手教程

    1.引入swiper.min.js和swiper.min.css两个文件,文件百度网盘下载地址链接:https://pan.baidu.com/s/1KwIzPfe9hFpSiMr5GqAWxw 提取 ...

  3. vue3中使用swiper完整版教程

    介绍 在 vue3 中使用 swiper, 实现轮播图的效果:如果组件样式等模块引入不当,很有可能导致,页面无效果:或者想要的箭头或者切换效果异常问题.具体使用方式如下所示: 使用方式 使用命令 np ...

  4. swiper组件如何自定义分页符和前进后退按钮

    前提 今天产品提了这样一个需求:用户在首次登录后,要展示一个引流的轮播图,其内容主要是对新功能的图文说明(类似于王者荣耀每次更新时的内容一览轮播图,如下图所示).如果非首次登录,则让它隐藏掉即可.注: ...

  5. Swiper插件 下载及使用教程

    首先附上官网地址:Swiper中文网-轮播图幻灯片js插件,H5页面前端开发 1. 进入官网,进入使用方法的页面: 2.下载插件压缩包: 下载方法一:点击"Swiper文件"下载插 ...

  6. php图片轮换功能,微信小程swiper组件实现图片轮播切换功能教程

    本文主要介绍了微信小程使用swiper组件实现图片轮播切换显示功能,涉及swiper组件相关属性使用技巧,希望能帮助到大家. 1.效果展示 2.关键代码 index.wxml: swiper组件属性说 ...

  7. Vue2系列教程——Swiper插件的使用

    Vue2 Swiper插件的使用 安装swiper 6.7.1 npm install swiper@6.7.1 --save npm install vue-awesome-swiper --sav ...

  8. Swiper 在网页开发中运用——简易教程

    Swper 初级使用 1导入两个文件在head部分 <script src="js/swiper/swiper.min.js"></script><l ...

  9. 微信小程序 swiper和weiper-itme组件的基本使用,微信小程序轮播图这么做教程

    1.swiper组件是干嘛的? 滑块视图容器.其中只可放置swiper-item组件,否则会导致未定义的行为. 2.swiper和swiper-itme怎么使用? 接下来我尝试教大家怎么使用swipe ...

最新文章

  1. 简单protobuf
  2. ios使用支付宝进行支付,注意事项 集成支付宝钱包支付iOS SDK的方法与经验。...
  3. 【转】Castle Windsor之组件注册
  4. Rabbitmq - 配置
  5. linq to entity常用操作
  6. 如何通过Python玩转小视频
  7. 用QXmlStreamWriter写入xml
  8. C++ STL 堆(heap)的初始化及其正确使用
  9. Python爬虫有哪些较好的书籍?
  10. ArgularJS和mdui的对话框冲突的解决方案
  11. h5分享到微信唤起app功能
  12. html文字段落i排版,i排版怎么修改字体 字体排版详细介绍
  13. java浏览器无数据,JAVA实现文件下载,浏览器端失去数据没反应
  14. Shiro 实现记住我功能
  15. linux穷举pppoe密码,Ubuntu/Linux下如何用rp-pppoe3.8通过ADSL上网
  16. Ubuntu下vim如何保存退出
  17. 代码审计之百家cms
  18. Visual Studio 2019 (VS2019)安装Spy++工具
  19. 使用HTML5自制视频控件
  20. .net core 不能更新数据

热门文章

  1. 一个Metro风格的开源项目 MahApps.Metro
  2. 关于mysql的行转列问题
  3. 一个程序员多年的收藏
  4. 一度智信:拼多多虚拟商品怎么运营
  5. PMP 管理学6大定律之五(布鲁克斯定律)
  6. 编写模板类时注意一点 2007-12-06 11:22
  7. 提升工作效率的软件及网站(不断更新中)
  8. 视觉检测设计与实践答题卡检测实验报告
  9. 怎么隐藏服务器真实IP地址?
  10. 运行深度学习出现Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize