經過對touch的基礎事件的封裝,能夠完成高級事件html
hammer.js http://hammerjs.github.io/git
方便使用移動端高級事件 (並且兼容性很好)github
中文文檔 http://www.javashuo.com/article/p-eukdjoej-er.htmlspa
swipe 快速滑code
pan 慢慢滑htm
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>touch</title> <style> .box{ width:90px; height:90px; background:pink; } </style> </head> <body> <div class="box" id="box"></div> <script src="hammer.min.js"></script> <script> var hammer=new Hammer(box); hammer.on("swipe pan tap doubletap press pinch rotate",function(e){ console.log(e.type); console.log(e); }); //可用於幻燈片 hammer.on("swiperight",function(e){ console.log("prev"); }); hammer.on("swipeleft",function(e){ console.log("next"); }); </script> </body> </html>