search

Home  >  Q&A  >  body text

javascript - hammer.js demo报错 caught TypeError: undefined is not a function

有人用过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>

  

怪我咯怪我咯2900 days ago457

reply all(5)I'll reply

  • 天蓬老师

    天蓬老师2017-04-10 14:51:44

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

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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-10 14:51:44

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

    reply
    0
  • 黄舟

    黄舟2017-04-10 14:51:44

    你好,这个问题解决没?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-10 14:51:44

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

    });

    reply
    0
  • 阿神

    阿神2017-04-10 14:51:44

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

    reply
    0
  • Cancelreply