any-wheel

增加鼠标滚轮事件的语义

Usage no npm install needed!

<script type="module">
  import anyWheel from 'https://cdn.skypack.dev/any-wheel';
</script>

README

watch-wheel

🖱️ 监控鼠标滚动

安装

yarn add watch-wheel

使用

import watchWheel from 'watch-wheel';
// 任意元素
const el = document.getElementById('any');

// 监视鼠标指针在该元素上触发的滚轮滚动.
watchWheel(el, (e) => {
    console.log(e.type); // wheelstart / wheelmove / wheelend
    console.log(e.delatY); // 鼠标滚轮滚动一下的距离
    console.log(e.velocityY); // 滚动速度, 每隔16ms取一次值
});

如果你的鼠标滚轮支持 x 轴滚动, 那么你还可以监听到delatXvelocityX的数值变化.