【问题标题】:Hammer js rotation direction锤子js旋转方向
【发布时间】:2023-03-21 09:22:01
【问题描述】:

我是 Hammer.js 的新手,并成功实现了旋转识别器:

    var image = document.getElementById('image');
    var manager = new Hammer(image);
    manager.get('rotate').set({ enable: true, threshold:3 });
    manager.on("rotate", function (event) {
      console.log(event.type + " gesture detected.");
    });

这个 sn-p 写入日志“检测到旋转手势”。

我的问题是如何检测旋转方向(向左或向右)?

【问题讨论】:

    标签: javascript hammer.js


    【解决方案1】:

    看看rotation in the event object - 它包含以度为单位的旋转角度(基于旋转方向的正或负)。所以这样的事情应该适合你:

    manager.on("rotate", function (event) {
      console.log(event.type + " gesture detected.");
      if(event.type === "rotate") {
          console.log("Rotation by " + event.rotation + " degrees.");
          if (event.rotation > 0) {
              console.log("Clockwise");
          } else {
              console.log("Counterclockwise");
          }
      }
    });
    

    【讨论】:

    • 是的,这就是我需要的)将标记为答案!谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-04
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    相关资源
    最近更新 更多