Swiper(Swiper master)是目前应用较广泛的移动端网页触摸内容滑动js插件,可以用来做轮播和滑动.

  • 初始化

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="swiper.css"/>
    <style>
    .swiper-container {
    width: 600px;
    height: 300px;
    }
    .swiper-slide{
    font-size: 50px
    }
    .swiper-slide:nth-of-type(1){
    background-color: cornflowerblue;
    }
    .swiper-slide:nth-of-type(2){
    background-color: coral;
    }
    .swiper-slide:nth-of-type(3){
    background-color: yellowgreen;
    }
    </style>
    </head>
    <body>
    <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>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div> <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div> <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
    </div>
    <!--导航等组件可以放在container之外--> <script src="swiper.js"></script>
    <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'vertical',
    // loop: true,
    //
    // // 如果需要分页器
    pagination: '.swiper-pagination',
    //
    // // 如果需要前进后退按钮
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    //
    // // 如果需要滚动条
    scrollbar: '.swiper-scrollbar',
    })
    </script>
    </body>
    </html>
  • 基本配置
    var mySwiper = new Swiper ('.swiper-container', {
    // 滑动方向
    // horizontal水平
    // vertical垂直
    direction: 'horizontal',
    // 初始化时候slide的索引(从0开始)
    initialSlide: 1,
    // 手指松开至slide贴合的时间
    speed:3000,
    // 设置自动播放的事件间隔
    autoplay: 2000,
    // 可显示数量
    slidesPerView:2,
    // 滑块居中
    centeredSlides:true,
    })
  • 触摸设置

      var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal', // 触摸距离与slide滑动距离的比率
    touchRatio:0.1, // 无法滑动
    onlyExternal:true, // 滑块跟随手指进行移动
    followFinger:false, // 定义longSwipesMs
    longSwipesMs:1000, longSwipes:false, shortSwipes:false, longSwipesRatio:0.5, touchAngle:10,
    })
    禁止切换和前进后退 <body>
    <div class="swiper-container">
    <div class="swiper-wrapper">
    <div class="swiper-slide stop">Slide 1</div>
    <!--<div class="swiper-slide swiper-no-swiping">Slide 2</div>-->
    <div class="swiper-slide">Slide 2</div>
    <div class="swiper-slide">Slide 3</div>
    </div>
    </div>
    <button class="prev">prev</button>
    <button class="next">next</button> <script src="swiper.js"></script>
    <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal',
    noSwiping:true,
    noSwipingClass : "stop",
    nextButton : ".next",
    prevButton : ".prev",
    })
    </script>
    分页器 <style>
    .swiper-container {
    width: 600px;
    height: 300px;
    }
    .swiper-slide{
    font-size: 50px
    }
    .swiper-slide:nth-of-type(1){
    background-color: cornflowerblue;
    }
    .swiper-slide:nth-of-type(2){
    background-color: coral;
    }
    .swiper-slide:nth-of-type(3){
    background-color: yellowgreen;
    }
    .swiper-pagination-bullet{
    width: 20px;
    height: 20px;
    }
    .swiper-pagination-bullet-active{
    background-color: yellow;
    }
    </style>
    </head>
    <body>
    <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>
    <div class="swiper-pagination"></div>
    </div> <script src="swiper.js"></script>
    <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal',
    pagination : ".swiper-pagination",
    paginationType : "bullets",
    paginationType : "fraction",
    paginationType : "progress",
    paginationClickable : true,
    paginationHide : true,
    paginationElement : "i",
    paginationBulletRender : function( swiper,index,classname ){
    return "<span class='"+ classname +"'>"+ (index+1) +"</span>"
    }
    })
    </script>
    </body>
    切换效果 <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal', effect : "slide",
    effect : "fade",
    effect : "cube",
    effect : "coverflow",
    effect : "flip",
    })
    </script>
    进程 <body>
    <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>
    </div>
    <button id="btn">按钮</button> <script src="swiper.js"></script>
    <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal', }) btn.onclick = function(){
    alert( mySwiper.progress );
    alert( mySwiper.slides[0].progress );
    console.log( mySwiper.slides[0].progress,mySwiper.slides[1].progress,mySwiper.slides[2].progress );
    } setInterval(function(){
    console.log( mySwiper.slides[0].progress,mySwiper.slides[1].progress,mySwiper.slides[2].progress );
    },20)
    </script>
    </body>
  • 常用属性和回调

    <body>
    <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>
    </div>
    <button id="btn">按钮</button>
    <script src="swiper.js"></script>
    <script>
    var mySwiper = new Swiper ('.swiper-container', {
    direction: 'horizontal', speed : 2000, onSlideChangeStart : function(){
    console.log( "开始滑动" );
    },
    onSlideChangeEnd : function(){
    console.log( "滑动结束" );
    }
    }) console.log( mySwiper.width );
    console.log( mySwiper.height ); btn.onclick = function(){
    console.log( mySwiper.translate );
    console.log( mySwiper.activeIndex );
    console.log( mySwiper.previousIndex );
    }
    </script>
    </body>

Swiper-轮播图。的更多相关文章

  1. Swiper轮播图

    今天咱们来说一下.Swiper轮播图. 超级简单的: 翠花,上代码:   <!DOCTYPE html>   <html lang="en">   < ...

  2. 微信小程序_(组件)swiper轮播图

    微信小程序swiper轮播图组件官方文档 传送门 Learn: swiper组件 一.swiper组件 indicator-dots:是否显示面板指示点[默认值false] autoplay:是否自动 ...

  3. swiper轮播图--兼容IE8

    //引入idangerous.swiper.min.js var mySwiper = new Swiper ('.swiper-container', { loop: true, paginatio ...

  4. 微信小程序之swiper轮播图中的图片自适应高度

    小程序中的轮播图很简单,官方都有例子的,但是唯一的缺陷就是swiper是固定死的150px高度,这样如果传入的图片大于这个高度就会被隐藏.辣么,怎样让图片自适应不同分辨率捏. 我的思路是:获取屏幕宽度 ...

  5. swiper 轮播图,拖动之后继续轮播

    在此贴出swiper官网地址:https://www.swiper.com.cn/api/index.html 示例如下(官网示例): <script> var mySwiper = ne ...

  6. swiper轮播图(逆向自动切换类似于无限循环)

    swiper插件轮播图,默认的轮播循序是会从右向左,第一张,第二张,第三张,然后肉眼可见是的从第三张从左到右倒回第一张,这样就会有些视觉体验不高, ,不过还是能够用swiper本身的特性更改成无限循环 ...

  7. 如何自定义微信小程序swiper轮播图面板指示点的样式

    https://www.cnblogs.com/myboogle/p/6278163.html 微信小程序的swiper组件是滑块视图容器,也就是说平常我们看到的轮播图就可以用它来做,不过这个组件有很 ...

  8. 自定义微信小程序swiper轮播图面板指示点的样式

    微信小程序的swiper组件是滑块视图容器,也就是说平常我们看到的轮播图就可以用它来做,不过这个组件有很多样式是固定的,但是,有时候我们的设计稿的面板指示点是需要个性化的,那么如何去修改swiper组 ...

  9. swiper轮播图插件

    一.简介 ①Swiper是纯javascript打造的滑动特效插件,面向手机.平板电脑等移动终端.Swiper能实现触屏焦点图.触屏Tab切换.触屏多图切换等常用效果. ②Swiper 是一款免费以及 ...

  10. vue2 使用 swiper 轮播图效果

    第一步.先安装swiper插件 npm install swiper@3.4.1 --save-dev 第二步.组件内引入swiper插件 import Swiper from 'swiper' im ...

随机推荐

  1. 一桩由X509Certificate2引发的血案

    A process serving application pool '. The data field contains the error number. 在某次网站更新后,发现wcf服务不可用了 ...

  2. sql 递归树

    with CTE as ( -->Begin 一个定位点成员 select ID, PersonName,ParentID,cast(PersonName as nvarchar(max)) a ...

  3. C/C++ -- Gui编程 -- Qt库的使用 -- Qt5试用

    1.头文件<QtGui>变成了<QtWidgets> 相应<QtGui/***>变成了<QtWidgets/***> 2.QTextCodec::set ...

  4. android学习-仿Wifi模块实现

    最近研究android内核-系统关键服务的启动解析,然而我也不知道研究wifi的作用,就当兴趣去做吧(其实是作业-_-) 系统原生WiFI功能大概有:启动WiFI服务,扫描WiFi信息(这个好像已经被 ...

  5. 正则表达式最后的/i是不区分大小写的意思

    eg: "/\/*install$/i" 正则表达式 代表什么意思   /表达式的内容/ ,php中的正则表达式都必须在 / / 内 \/是匹配"/" 号,*号 ...

  6. js拼图

    ;(function($){ function arrayIndexOf(r, num){ if( Array.prototype.indexOf ){ return r.indexOf(num); ...

  7. C# 新建 exe文件,并且自定义协议从浏览器中启动该程序

    1. C# 新建一个 exe 文件: 打开你的 vs ,[文件] ---> [新建] ---> [项目] 选择 Windows 窗体应用,并起一个名字: 接着该文件会在当前项目的 myap ...

  8. UIKit 框架之UICollectionView

    1.自定义UICollectionViewCell 在myCollectionViewCell.h中声明两个属性 // // myCollectionViewCell.h // UICollectio ...

  9. sql视图中写case判断null值

    下面是正解 用 is null (case when dbo.Feedback.Funnel is null then '否' when dbo.Feedback.Funnel='否' then '是 ...

  10. ArchLinux - 安装指南

    Step 1 将镜像写入u盘 u盘从来不是唯一的选择,但多数人可能喜欢这么做. 我是在OS X上进行操作,如果你用的是windows,也许可以使用Image Writer for Windows或者U ...