移动端事件(其余触摸事件)hammer.js

经过对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>

相关文章
相关标签/搜索