javascript swiper select 特定的 swiper 元素

javascript swiper select particular swiper element

如何在 javascript 中的特定刷卡元素上捕捉 select/touch-event?

这个想法是让用户使用滑动功能浏览一组图像并进行特定选择。然后,该选择将用于代码中的其他地方。

在下面的代码示例中,我想捕获一个事件以防万一'Slide 9' 被按下。

这在某种程度上暗示了如何区分幻灯片触摸和 press/release 事件触摸的问题。 非常感谢

   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>Multiple Swipers</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>

   <body>
      <div class = "views">
         <div class = "view view-main">
            <div class = "pages">
               <div data-page = "home" class = "page navbar-fixed">

                  <div class = "navbar">
                     <div class = "navbar-inner">
                        <div class = "left"> </div>
                        <div class = "center">Multiple Swipers</div>
                        <div class = "right"> </div>
                     </div>
                  </div>

                  <div class = "page-content">


                     <div class = "content-block-title">4 Slides Per View, 10px Between</div>
                     <div class = "swiper-container swiper-4">
                        <div class = "swiper-pagination"></div>
                        <div class = "swiper-wrapper">
                           <div class = "swiper-slide"><span>Slide 1</span></div>
                           <div class = "swiper-slide"><span>Slide 2</span></div>
                           <div class = "swiper-slide"><span>Slide 3</span></div>
                           <div class = "swiper-slide"><span>Slide 4</span></div>
                           <div class = "swiper-slide"><span>Slide 5</span></div>
                           <div class = "swiper-slide"><span>Slide 6</span></div>
                           <div class = "swiper-slide"><span>Slide 7</span></div>
                           <div class = "swiper-slide"><span>Slide 8</span></div>
                           <div class = "swiper-slide"><span>Slide 9</span></div>
                           <div class = "swiper-slide"><span>Slide 10</span></div>
                        </div>
                     </div>



                  </div>
               </div>
            </div>
         </div>
      </div>

      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>

      <style>
         .swiper-slide {
            background:#fff;
            box-sizing:border-box;
            border:1px solid #ccc;
            line-height:120px;
            text-align:center;
         }

         .swiper-slide span {
            font-size:17px;
         }
         .swiper-container {
            height:120px;
            margin:0px 0 35px;
         }
      </style>

      <script>
         var myApp = new Framework7();

         // 4 Slides Per View, 10px Between
         var mySwiper4 = myApp.swiper('.swiper-4', {
            pagination:'.swiper-4 .swiper-pagination',
            spaceBetween: 10,
            slidesPerView: 4,
         });
      </script>
   </body>

</html>

在滑块的点击动作上使用mySwiper.activeIndex获取被点击幻灯片的索引号。

http://idangero.us/swiper/api/#methods