如何在javascript中捕获特定swiper元素上的select / touch-event?
我们的想法是让用户使用滑动功能浏览一组图像并进行特定选择。然后,该选择应在代码的其他地方使用。
在下面的代码示例中,我想抓住一个事件,例如'幻灯片9'被按下了。
这意味着如何区分幻灯片的触摸和按下/释放事件的触摸的问题。 非常感谢
<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>
答案 0 :(得分:0)
对滑块的点击操作使用mySwiper.activeIndex
以获取所点击幻灯片的索引号。