javascript - hammer.js demo报错 caught TypeError: undefined is not a function
怪我咯
怪我咯 2017-04-10 14:49:44
0
5
462

有人用过hammer.js 这个插件么,能否提供一个demo?按照官网上的demo就没有成功过,总是报错caught TypeError: undefined is not a function ,自己写的demo如下,不知道有什么地方出错了,Thx

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<script type="text/javascript" src="/js/hammer.js"></script>
<style>
  .hitarea{width:300px;height:300px;background-color:red;} 
</style>
</head>
<body>
<p  id="hitarea" class="hitarea"></p>
<script> 
   var container= document.getElementById("hitarea");
   var hammertime = new Hammer(container, {
      preventDefault: true,
      gesture: true
  });
   hammertime.on("swipeleft", function(){
    alert("swipeleft");
  });
   hammertime.on("swiperight", function(){
    alert("swiperight");
  });
</script>
</body>
</html>

  

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(5)
Peter_Zhu

这是一个手势相关的库,官网地址:http://hammerjs.github.io/

我下载了官网的压缩脚本,运行了您的程序,没报错,程序也能按照期望能运行,运行截图如下:

左手右手慢动作

我运行了下,没发现有错误,可以正常运行。

黄舟

你好,这个问题解决没?

伊谢尔伦

<script>标签下面加入下面的东西,后面代码都写在里面
window.addEventListener('load',function(){

});

阿神

我也遇到同样的问题,不知道什么原因

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板