JSPM

watch-wheel

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q32612F
  • License ISC

增加鼠标滚轮事件的语义

Package Exports

  • watch-wheel
  • watch-wheel/dist/index.es.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (watch-wheel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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的数值变化.