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. 网络游戏程序员须知 UDP vs TCP(转)

    本文为作者原创或翻译,转载请注明,不得用于商业用途. 作者:rellikt@gmail.com 首发链接:http://blog.csdn.net/rellikt/archive/2010/08/21 ...

  2. webpack处理url资源的配置

    webpack处理url资源的配置 1.安装 npm i url-loader -D 2.修改webpack.config.js const path = require('path'); // 启用 ...

  3. UBUNTU 下 APACHE2 Too many open files: Error retrieving pid file /var/run/apache2.pid

    cat /proc/sys/fs/file-max 系统可打开的最大文件个数 ulimit -n 当前系统限制的个数 ulimit -n 10240 调整当前系统的限制 修改/etc/sysctl.c ...

  4. win10下用Linux搭建python&nodejs开发环境

    Win10下用自带Linux系统搭建开发环境 Win10下用自带Linux系统搭建开发环境启用Linux老版本(win10 1709之前):新版本(win10 1709之后)卸载linux老版本新版本 ...

  5. Java 生成指定范围的随机数

    /** * 生成[min, max]之间的随机整数 * * @param min 最小整数 * @param max 最大整数 * @return * @author jqlin */ private ...

  6. windows server 2012 如何开启 hyper-v 并创建虚拟机

    当我们拿到一台新的windows server 2012 服务器的时候,默认hyper-v是没有开启的,如果我们要在windows server上面创建虚拟机,那么我们也就需要开启hyper-v. 开 ...

  7. java的if语句,少于一行可以省略大括号

    我们认识的 if 语句,大概是这样的: if(条件){ 语句1; }else{ 语句2; } 如果要执行的语句少于1行,大括号是可以省略的 可以让程序更简洁和美观 if(条件){ 语句1; 语句2; ...

  8. 源码速读及点睛:HashMap

    Java 8 HashMap的分离链表 从Java 2到Java 1.7,HashMap在分离链表上的改变并不多,他们的算法基本上是相同的.如果我们假设对象的Hash值服从平均分布,那么获取一个对象需 ...

  9. [转]wx.getUserInfo(OBJECT) 微信小程序 获取用户信息

    本文转自:http://mp.weixin.qq.com/debug/wxadoc/dev/api/open.html wx.getUserInfo(OBJECT) 获取用户信息,withCreden ...

  10. AngularJS内建服务以及自定义服务的用法

    在AngularJS中, 服务是一个比较重要的部分,它是一个对象或者是函数,可以在你的AngularJS的应用中使用.接下来介绍几种比较常用的内建服务以及自定义服务的方法. [内建服务] (1)loc ...