hammer.js is a open-source library that can recognize gestures made by touch, mouse and pointerEvents. It doesn’t have any dependencies, and it’s small, only 3.96 kB minified + gzipped!

  • 捕捉鼠标事件(点击,双击,拖动)产生动画效果。
  • API提供了丰富的动效
  • jQuery类的使用方法
1
2
3
4
5
6
7
8
9
10
var myElement = document.getElementById('myElement');
// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer(myElement);
// listen to events...
mc.on("panleft panright tap press", function(ev) {
myElement.textContent = ev.type +" gesture detected.";
});