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. 2018春招-今日头条笔试题-第二题(python)

    题目描述:2018春招-今日头条笔试题5题(后附大佬答案-c++版) 解题思路: 利用深度优先搜索 #-*- coding:utf-8 -*- class DFS: ''' num:用于存储最后执行次 ...

  2. 0day发布网站[转载]

    1.中文版http://www.wooyun.org/index.php2.中文版http://www.sitedirsec.com/3.http://www.sebug.net/ http://ww ...

  3. Android4.0 Launcher 源码分析2——Launcher内容加载绑定详细过程

    Launcher在应用启动的时候,需要加载AppWidget,shortcut等内容项,通过调用LauncherModel.startLoader(),开始加载的工作.launcherModel中加载 ...

  4. Java虚拟机(一):JVM简介

    JVM简介 Java虚拟机(JVM)是由Java虚拟机规范定义的,其上运行的是字节码指令集.这种字节码指令集包含一个字节的操作码(opcode),零至多个操作数(oprand),虚拟机规范明确定义了每 ...

  5. Go 压测

    1. 单测 + 压测 压测 go test -bench=. -benchmem 单元测试 go test -v . 2. pprof + 火焰图(查看cpu占用,内存占用) 嵌入代码 import ...

  6. php发送get请求

    感谢:http://www.zoneself.org/2014/07/21/content_2665.html 1.用PHP发送get请求,很简单: <?php $url='http://www ...

  7. 面试题-----求单链表的倒数第k个节点

    #include <iostream> using namespace std; struct node{ int value; struct node *next; }; struct ...

  8. Eclipse内存讲解,eclipse.ini设置

    Ubuntu 系统下,Eclipse 配置文件: vi ~/eclipse/eclipse.ini -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:Max ...

  9. c语言----<项目>_小游戏<2048>

    2048 小游戏 主要是针对逻辑思维的一个训练. 主要学习方面:1.随机数产生的概率.2.行与列在进行移动的时候几种情况.3.MessageBox的使用 #include <iostream&g ...

  10. 马尔科夫随机场(Markov Random Field)

    马尔可夫随机场(Markov Random Field),它包含两层意思:一是什么是马尔可夫,二是什么是随机场. 马尔可夫过程可以理解为其当前的状态只与上一刻有关而与以前的是没有关系的.X(t+1)= ...