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. Visual Studio 2015中使用gdb远程调试linux程序

    VS的debug功能非常强大,相比而言linux上的图形化调试一直不是很好用. 如果可以使用VS来调试linux程序,应该是一件比较愉快的事情. 这在2015中变得可能,因为从2015开始VS支持An ...

  2. require/load/include/extend的区别

    require 一般用于加载一个库,当多次使用require加载一个库时,只有第一次有效,后面的都会加载失败,也就是会返回"false",以为require会追踪文件是否被加载. ...

  3. 关于Spring配置的一些东西

    Spring 配置的三种方式:JAVA配置,注解配置,和XML的配置 注解配置: @Service:标识服务层(业务层)组件 @Component:基本注解, 标识了一个受 Spring 管理的组件( ...

  4. Go语言学习笔记七: 函数

    Go语言学习笔记七: 函数 Go语言有函数还有方法,神奇不.这有点像python了. 函数定义 func function_name( [parameter list] ) [return_types ...

  5. centos7-安装mysql5.6.36

    本地安装了mysql5.7, 但和springboot整合jpa时会出现 hibernateException, 不知道为什么, 换个mysql5.6版本的mysql,  源码安装, cmake一直过 ...

  6. springboot-13-junitTest

    junitTest, 提喜欢用的一个方法, 在测试代码时非常好用 1, 添加maven依赖 <!-- 加入spring-test依赖 --> <dependency> < ...

  7. prometheus安装、使用

    本文主要参考https://songjiayang.gitbooks.io/prometheus/introduction/what.html 二进制包安装 我们可以到 Prometheus 二进制下 ...

  8. vue-webpack 做出来的项目部署到服务器上,点开是空白页(我这里把项目发布到git上)

    总结1: 从网上下的很多demo,用npm run dev 就可以启动项目,比如:vue-cli,为什么?因为vue-cli自动帮我们安装了express服务器. 总结2: npm run dev 是 ...

  9. 浅谈JS中的!=、== 、!==、===的用法和区别

    var num = 1;     var str = '1';     var test = 1;     test == num  //true 相同类型 相同值     test === num ...

  10. NodeJS之 Express框架 app.use(express.static)

    一 .设置静态文件目录 语法如下: app.use(express.static(_dirname + '/public')); //设置静态文件目录 注: 将静态文件目录设置为项目根目录 + ‘/p ...