Gem*_*nes 4 javascript hammer.js
当用户在触摸设备上执行操作时,我使用 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;
});
})
Run Code Online (Sandbox Code Playgroud)
滑动可用于所有方向。
使用swipeleft和swiperright进行水平滑动,使用 swipeup 和swipedown进行垂直滑动。
$(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');
});
}) Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9544 次 |
| 最近记录: |