- touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发。
- touchmove事件:当手指在屏幕上滑动的时候连续地触发。在这个事件发生期间,调用preventDefault()事件可以阻止滚动。
- touchend事件:当手指从屏幕上离开的时候触发。
- touchcancel事件:当系统停止跟踪触摸的时候触发。关于这个事件的确切出发时间,文档中并没有具体说明,咱们只能去猜测了。
知道了这些事件那么就可以直接利用,直接得出滑动距离
-
var notice = document.getElementById("notice"); notice.addEventListener('touchmove', function (e) { let touch_height = document.documentElement.scrollTop; console.log("滑动距离为:", touch_height); });