广告
返回顶部
首页 > 资讯 > 前端开发 > node.js >js插件Swiper有什么用
  • 392
分享到

js插件Swiper有什么用

2024-04-02 19:04:59 392人浏览 安东尼
摘要

小编给大家分享一下js插件Swiper有什么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! Sw

小编给大家分享一下js插件Swiper有什么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

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

  • 初始化

    <!DOCTYPE html><html>
      <head>  <meta charset="UTF-8">  <title></title>  <link rel="stylesheet" type="text/CSS" href="swiper.css?1.1.11"/>  <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?1.1.11"></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?1.1.11"></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?1.1.11"></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?1.1.11"></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?1.1.11"></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>

以上是“js插件Swiper有什么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网node.js频道!

--结束END--

本文标题: js插件Swiper有什么用

本文链接: https://www.lsjlt.com/news/81509.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • js插件Swiper有什么用
    小编给大家分享一下js插件Swiper有什么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! Sw...
    99+
    2022-10-19
  • vue项目中怎么导入swiper插件
    这篇文章给大家介绍vue项目中怎么导入swiper插件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。安装安装swiper3的最新版本3.4.2:npm i swip...
    99+
    2022-10-19
  • Angular.js中使用Swiper插件不能滑动怎么办
    小编给大家分享一下Angular.js中使用Swiper插件不能滑动怎么办,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!我们都知道swiper是交互体验十分好的轮播插件但是通过angula...
    99+
    2022-10-19
  • vue中怎么使用vue-awesome-swiper轮播图插件
    vue中怎么使用vue-awesome-swiper轮播图插件,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。第一步安装npm ins...
    99+
    2022-10-19
  • vue的vue-awesome-swiper轮播图插件怎么使用
    这篇文章主要讲解了“vue的vue-awesome-swiper轮播图插件怎么使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“vue的vue-awesome-swiper轮播图插件怎么使用...
    99+
    2023-07-04
  • 在vue项目中使用Swiper插件详解
    目录vue项目使用Swiper插件第一步:下载Swiper插件 第二步:在对应的组件页面中导入该插件第三步: 编写对应的html部分第四步:在data中配置对应的参数vue...
    99+
    2023-01-14
    vue Swiper vue使用Swiper插件 vue Swiper插件
  • vue使用swiper插件实现垂直轮播图
    目录使用swiper插件做垂直轮播图swiper轮播插件使用 一次显示多个slidesSwiper 动态加载数据遇到的坑总结使用swiper插件做垂直轮播图 1.下载安装 cnpm ...
    99+
    2023-01-14
    vue使用swiper插件 vue垂直轮播图 vue swiper插件
  • 如何分析Swiper插件的原理和使用
    今天给大家介绍一下如何分析Swiper插件的原理和使用。文章的内容小编觉得不错,现在给大家分享一下,觉得有需要的朋友可以了解一下,希望对大家有所帮助,下面跟着小编的思路一起来阅读吧。Swiper介绍swiper是一款开源的解决前端开发中触摸...
    99+
    2023-06-29
  • ngAnimate插件有什么用
    这篇文章主要介绍ngAnimate插件有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!ngAnimate插件是做什么的?ngAnimate插件如其名字一样是为元素提供动画的。怎...
    99+
    2022-10-19
  • vue使用swiper插件实现轮播图的示例
    目录vue - 使用swiper插件实现轮播图 使用watch与$nextTick解决轮播的Bug hello大家好,最近我在做一个仿饿了么的项目,我会将我的项目经验同步到这里,与大...
    99+
    2022-11-12
  • vue中如何使用轮播图插件vue-awesome-swiper
    这篇文章主要介绍了vue中如何使用轮播图插件vue-awesome-swiper,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。Vue-Awe...
    99+
    2022-10-19
  • 解决vue中使用swiper 插件出错的问题
    由于我自己在写一个demo时候用到了该插件,出现了一些问题,所以就简单查了一下该插件的用法以及一些常见的错误 1.出现Get .../maps/swiper.min.js.map 5...
    99+
    2022-11-12
  • gulp-changed插件有什么用
    这篇文章将为大家详细讲解有关gulp-changed插件有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。前言gulp-changed插件的作用,是用来过滤未被修改过...
    99+
    2022-10-19
  • jQuery插件ajaxFileUpload有什么用
    jQuery插件ajaxFileUpload是用于实现文件上传功能的插件。通过使用ajaxFileUpload插件,可以在不刷新页面...
    99+
    2023-08-18
    jQuery ajaxFileUpload
  • react有什么插件
    这篇文章主要介绍了react有什么插件的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇react有什么插件文章都会有所收获,下面我们一起来看看吧。 r...
    99+
    2022-10-19
  • 一起来了解下Swiper插件的使用和介绍
    目录Swiper介绍swiper的使用代码实现总结Swiper介绍 swiper是一款开源的解决前端开发中触摸滑动案例的插件 swiper官网: swiper的使用 使用swipe...
    99+
    2022-11-13
  • JS中oncontextmenu事件有什么用
    oncontextmenu事件用于在用户右击元素时触发的事件。它可以用于自定义右键菜单、阻止默认的上下文菜单、执行特定的操作等。以下...
    99+
    2023-10-11
    JS
  • JS条形码插件JsBarcode怎么用
    小编给大家分享一下JS条形码插件JsBarcode怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!具体如下:这里介绍一下在G...
    99+
    2022-10-19
  • js时间查询插件怎么用
    这篇文章主要为大家展示了“js时间查询插件怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“js时间查询插件怎么用”这篇文章吧。首先要引入js文件和css文件...
    99+
    2022-10-19
  • webpack4中splitChunk插件有什么用
    这篇文章主要介绍webpack4中splitChunk插件有什么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!常用参数minSize(默认是30000):形成一个新代码块最小的体积...
    99+
    2022-10-19
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作