如何获得touchmove的最后位置?

时间:2019-07-17 09:08:12

标签: javascript touch-event dom-events touchstart touchmove

我正在尝试使用控制台显示。将时间记录在图表顶部,让我们看看 我的屏幕:

当我将函数与touchmove事件一起使用时,我可以执行此操作,但是我想在圆圈停止转弯时将最后一小时保持在顶部,我什至不知道如何使用函数执行此操作使用事件touchend

让我们看看我的代码:

function turnitoff() {
  var R2D, active, angle, center, init, rotate, rotation, start, startAngle, stop;

  active = false;
  angle = 0;
  var target = document.getElementById('target');
  rotation = 0;

  startAngle = 0;

  center = {
    x: 0,
    y: 0
  };

  init = function() {
    target.addEventListener("touchstart", start, false);
    target.addEventListener("touchmove", rotate, false);
    return target.addEventListener("touchend", stop, false);
  };

  R2D = 180 / Math.PI;

  start = function(e) {
    var height, left, top, width, x, y, _ref;
    _ref = this.getBoundingClientRect(), top = _ref.top, left = _ref.left, height = _ref.height, width = _ref.width;
    center = {
      x: left + (width / 2),
      y: top + (height / 2)
    };
    x = e.touches[0].clientX - center.x;
    y = e.touches[0].clientY - center.y;
    startAngle = R2D * Math.atan2(y, x);
    return active = true;
  };

  rotate = function(e) {
    var d, x, y;
    x = e.touches[0].clientX - center.x;
    y = e.touches[0].clientY - center.y;
    d = R2D * Math.atan2(y, x);
    rotation = d - startAngle;
    var resultat1 = (angle + rotation) / 360
    var resultat2 = resultat1 - Math.floor(resultat1)
    var resultat3 = 24 - (resultat2 * 24)
    console.log(resultat3)
    if (active) {
      return this.style.webkitTransform = "rotate(" + (angle + rotation) + "deg)";
    }
    return this.resultat3
  };

  stop = function() {
    angle += rotation;
    return active = false;
  };

  init();
}

rotate用于我的touchmovestop用于我的touchend

0 个答案:

没有答案