当用户在触摸设备上执行操作时,我使用hammer.js来重置我的计时器。这与水龙头,按压和水平滑动很好,但我如何才能让它识别垂直滑动?
$(function () {
var page = document.getElementById("parent");
Hammer(page).on("swipe", function () {
idleTime = 0;
});
Hammer(page).on("tap", function () {
idleTime = 0;
});
Hammer(page).on("press", function () {
idleTime = 0;
});
}) 发布于 2016-08-12 12:12:23
滑动是面向各个方向的。
使用和进行水平滑动,使用swipeup,使用向下滑动进行垂直滑动。
$(function () {
var element = document.getElementById("parent");
var mc = new Hammer(element);
mc.get('swipe').set({ direction: Hammer.DIRECTION_ALL });
mc.on("swipeleft", function () {
alert('swipeleft');
});
mc.on("swiperight", function () {
alert('swiperight');
});
mc.on("swipeup", function () {
alert('swipeup');
});
mc.on("swipedown", function () {
alert('swipedown');
});
}) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="http://hammerjs.github.io/dist/hammer.min.js"></script>
<div id="parent" style="width:100%;height:500px;background:#ff0000;"></div>
https://stackoverflow.com/questions/38917595
复制相似问题