查看: 2133|回复: 5
打印 上一主题 下一主题

求助,点击图片滑动到指定slide

[复制链接]

该用户从未签到

1

主题

5

帖子

17

积分

新手上路

Rank: 1

积分
17
跳转到指定楼层
楼主
发表于 2015-7-6 12:53:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何实现,点击某图片滑动到指定slide呢?
是用mySwiper.slideTo(index, speed, runCallbacks)吗?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖
回复

使用道具 举报

该用户从未签到

1

主题

4

帖子

53

积分

注册会员

Rank: 2

积分
53
沙发
发表于 2015-7-7 01:06:52 | 只看该作者
用这个 mySwiper.slideTo(index, speed, runCallbacks)
下标从0开始

eg:  mySwiper.slideTo(2)  换到第三个

点评

谢谢  发表于 2015-7-10 15:32

评分

参与人数 1金钱 +20 收起 理由
admin + 20 很给力!

查看全部评分

回复 支持 反对

使用道具 举报

该用户从未签到

1

主题

5

帖子

17

积分

新手上路

Rank: 1

积分
17
板凳
 楼主| 发表于 2015-7-9 21:08:02 | 只看该作者
swiperbbs 发表于 2015-7-7 01:06
用这个 mySwiper.slideTo(index, speed, runCallbacks)
下标从0开始

比如这个里在img怎么写呢?

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.      <meta charset="utf-8">
  5.          <meta name="viewport" content="width=device-width, initial-scale=1" />
  6.         <!--[if lt IE 9]>
  7.     <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
  8.   <![endif]-->
  9.     <!--meta name="viewport" content="width=320,minimum-scale=0.5, maximum-scale=5, user-scalable=no"-->
  10.     <title>办证微指南</title>
  11. <!--meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'/-->
  12. <link rel="stylesheet" href="css/swiper.min.css">
  13. <link rel="stylesheet" href="css/animate.min.css">


  14. <!--<link rel="stylesheet" href="/dist/css/swiper.min.css">
  15. <link rel="stylesheet" href="/dist/css/animate.min.css">
  16. <script src="/dist/js/swiper.min.js"></script>
  17. <script src="/dist/js/swiper.animate.min.js"></script>-->

  18. <style>
  19. *{
  20.         margin:0;
  21.         padding:0;
  22. }
  23. html,body{
  24.         height:100%;
  25. }
  26. body{
  27.         font-family:"microsoft yahei";
  28. }
  29. .swiper-container {
  30.   /*  width: 320px;
  31.     height: 480px;*/
  32.         width: 100%;
  33.     height: 100%;
  34.         background:#fff;

  35.   
  36. }  

  37. .swiper-slide{
  38.         width:100%;
  39.         height:100%;
  40.        
  41.         background-size:100% 100%;

  42. }
  43. img { max-width: 100%;}
  44. img{
  45.         display:block;
  46. }
  47. .swiper-pagination-bullet {
  48. width: 6px;
  49. height: 6px;
  50. background: #fff;
  51. opacity: .4;
  52. }
  53. .swiper-pagination-bullet-active {
  54. opacity: 1;
  55. }
  56. @-webkit-keyframes start {
  57.         0%,30% {opacity: 0;-webkit-transform: translate(0,10px);}
  58.         60% {opacity: 1;-webkit-transform: translate(0,0);}
  59.         100% {opacity: 0;-webkit-transform: translate(0,-8px);}
  60. }
  61. @-moz-keyframes start {
  62.         0%,30% {opacity: 0;-moz-transform: translate(0,10px);}
  63.         60% {opacity: 1;-moz-transform: translate(0,0);}
  64.         100% {opacity: 0;-moz-transform: translate(0,-8px);}
  65. }
  66. @keyframes start {
  67.         0%,30% {opacity: 0;transform: translate(0,10px);}
  68.         60% {opacity: 1;transform: translate(0,0);}
  69.         100% {opacity: 0;transform: translate(0,-8px);}
  70. }
  71. .ani{
  72.         position:absolute;
  73.         }
  74. .txt{
  75.         position:absolute;
  76. }
  77. #array{
  78.         position:absolute;z-index:999;-webkit-animation: start 1.5s infinite ease-in-out;
  79. }
  80. </style>
  81. </head>

  82. <body>
  83. <script src="js/swiper.min.js"></script>
  84. <script src="js/swiper.animate.min.js"></script>




  85. <div class="swiper-container">
  86.     <div class="swiper-wrapper">
  87.        
  88.     <!-------------slide1----------------->
  89.             <section class="swiper-slide swiper-slide1">
  90.         <img  src="upload/新证入网十日办结.png" class="ani resize" style="width:320px;height:43px;left:0px;top:30px;z-index:3;" swiper-animate-effect="zoomIn" swiper-animate-duration="1.5s" swiper-animate-delay="0s" mySwiper.slideTo(11) >
  91.         <img src="upload/长乐市烟草专卖局.jpg" class="ani resize" style="width:320px;height:27px;left:0px;top:75px;z-index:3;" swiper-animate-effect="fadeIn" swiper-animate-duration="0.5s" swiper-animate-delay="1.5s"  >
  92.         <img src="upload/免费办证方便快捷.png" class="ani resize" style="width:320px;height:188px;left:0;top:140px;z-index:2;" swiper-animate-effect="rotateInDownLeft" swiper-animate-duration="0.5s" swiper-animate-delay="2s"   >
  93.         <img src="upload/卷烟包装.png"  class="ani resize" style="width:320px;height:188px;left:0px;top:140px;z-index:1;" swiper-animate-effect="bounceInDown" swiper-animate-duration="1.5s" swiper-animate-delay="2.5s"  >
  94.         <img src="upload/首先.png"  class="ani resize" style="width:320px;height:112px;left:0px;top:320px;z-index:1;" swiper-animate-effect="fadeInUp" swiper-animate-duration="0.5s" swiper-animate-delay="4s" >
  95.                 </section>

  96.      <!---------------slide2-------------->
  97.         <section class="swiper-slide swiper-slide2">
  98.         <img src="upload/您需要准备以下材料.png" class="ani resize" style="width:320px;height:43px;left:0px;top:10px;z-index:3; " swiper-animate-effect="bounce" swiper-animate-duration="0.5s" swiper-animate-delay="0s"  >
  99.                 <img src="upload/行政许可申请书1份(由管理所提供).png" class="ani resize" style="width:320px;height:21px;left:10px;top:80px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0.5s"  >
  100.                 <img src="upload/您的个人免冠肖像照片1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:122px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="1s"  >
  101.                 <img src="upload/您的居民身份证复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:164px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="1.5s"  >
  102.                 <img src="upload/店面的产权证明复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:206px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="2s"  >
  103.                 <img src="upload/店面的租赁合同复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:248px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="2.5s"  >
  104.                 <img src="upload/工商营业执照复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:290px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="3s"  >
  105.                 <img src="upload/资金证明复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:332px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="3.5s"  >
  106.                 <img src="upload/委托授权书1份(由他人代办时).png" class="ani resize" style="width:320px;height:21px;left:10px;top:374px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="4s"  >   
  107.         </section>
  108.      <!----------------slide3-------------->
  109.         <section class="swiper-slide swiper-slide3">
  110.         <img src="upload/行政许可申请书1份(由管理所提供).png" class="ani resize" style="width:320px;height:21px;left:10px;top:10px;z-index:4; " swiper-animate-effect="bounce" swiper-animate-duration="0.5s" swiper-animate-delay="0s"  >
  111.                 <img src="upload/申请书.png" class="ani resize" style="width:320px;height:400px;left:10px;top:40px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0.5s"  >
  112.         </section>
  113.         <!-------------slide4----------------->
  114.         <section class="swiper-slide swiper-slide4">
  115.                
  116.         <img src="upload/您的个人免冠肖像照片1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:10px;z-index:4; " swiper-animate-effect="bounce" swiper-animate-duration="0.5s" swiper-animate-delay="0s"  >
  117.                 <img src="upload/照片.png" class="ani resize" style="width:320px;height:400px;left:10px;top:40px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0.5s"  >
  118.         </section>
  119.                 <!-------------slide5----------------->
  120.         <section class="swiper-slide swiper-slide4">
  121.         <img src="upload/您的居民身份证复印件1张.png" class="ani resize" style="width:320px;height:21px;left:10px;top:10px;z-index:4; " swiper-animate-effect="bounce" swiper-animate-duration="0.5s" swiper-animate-delay="0s"  >
  122.                 <img src="upload/身份证.png" class="ani resize" style="width:320px;height:400px;left:10px;top:40px;z-index:4;" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0.5s"  >
  123.         </section>

  124.         
  125.     </div>
  126.    
  127.        
  128.    <img src="images/arrow1.png" style="width:20px;height:15px; top:460px; left:150px;" id="array" class="resize">
  129.   <div class="swiper-pagination"></div>  
  130. </div>


  131. <script>  

  132. scaleW=window.innerWidth/320;
  133. scaleH=window.innerHeight/480;
  134. var resizes = document.querySelectorAll('.resize');
  135.           for (var j=0; j<resizes.length; j++) {
  136.            resizes[j].style.width=parseInt(resizes[j].style.width)*scaleW+'px';
  137.                    resizes[j].style.height=parseInt(resizes[j].style.height)*scaleH+'px';
  138.                    resizes[j].style.top=parseInt(resizes[j].style.top)*scaleH+'px';
  139.                    resizes[j].style.left=parseInt(resizes[j].style.left)*scaleW+'px';
  140.           }
  141.                   
  142.   var mySwiper = new Swiper ('.swiper-container', {
  143.    direction : 'vertical',
  144.    loop : false,
  145.    pagination: '.swiper-pagination',
  146.    keyboardControl : true,

  147.   //virtualTranslate : true,
  148.    mousewheelControl : true,
  149.    onInit: function(swiper){
  150.    swiperAnimateCache(swiper);
  151.    swiperAnimate(swiper);
  152.           },
  153.    onSlideChangeEnd: function(swiper){
  154.         swiperAnimate(swiper);
  155.     },
  156.         onTransitionEnd: function(swiper){
  157.         swiperAnimate(swiper);
  158.     },
  159.        
  160.        
  161.         watchSlidesProgress: true,

  162.       onProgress: function(swiper){
  163.         for (var i = 0; i < swiper.slides.length; i++){
  164.           var slide = swiper.slides[i];
  165.           var progress = slide.progress;
  166.           var translate = progress*swiper.height/4;  
  167.                   scale = 1 - Math.min(Math.abs(progress * 0.5), 1);
  168.           var opacity = 1 - Math.min(Math.abs(progress/2),0.5);
  169.           slide.style.opacity = opacity;
  170.                   es = slide.style;
  171.                   es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = 'translate3d(0,'+translate+'px,-'+translate+'px) scaleY(' + scale + ')';

  172.         }
  173.       },
  174.        
  175.            onSetTransition: function(swiper, speed) {
  176.         for (var i = 0; i < swiper.slides.length; i++){
  177.           es = swiper.slides[i].style;
  178.                   es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = speed + 'ms';

  179.         }
  180.       },
  181.        
  182.        
  183.        
  184.            })
  185.              
  186.   </script>


  187. </body>
  188. </html>

复制代码


回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

11

帖子

56

积分

注册会员

Rank: 2

积分
56
地板
发表于 2015-7-10 15:29:59 | 只看该作者
我也想知道,不知楼主有方法了没啊
回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

11

帖子

56

积分

注册会员

Rank: 2

积分
56
5#
发表于 2015-7-10 15:32:48 | 只看该作者
楼主,mySwiper.slideTo(2) 这个挺好使的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Swiper中文网 ( 粤ICP备15001020号

GMT+8, 2024-5-2 19:11 , Processed in 0.108444 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表