当前位置: 移动技术网 > IT编程>网页制作>CSS > 移动端事件(其他触摸事件)hammer.js

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

2020年03月16日  | 移动技术网IT编程  | 我要评论

通过对touch的基础事件的封装,可以完成高级事件

 

hammer.js  

方便使用移动端高级事件 (而且兼容性很好)

 

 

中文文档 

 

swipe 快速滑

pan 慢慢滑

<!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>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网