K
K
krll-k2015-09-11 22:49:40
JavaScript
krll-k, 2015-09-11 22:49:40

Why are touchstart, touchmove, touchend values ​​shown relative to the viewport and not relative to the selected element?

var el = document.createElement("div");
el.addEventListener('touchmove', function(event){
  if(event.targetTouches.length==1){
    var touch = event.targetTouches[0];
    console.log(touch.pageX+"px,"+touch.pageY+"px");
  }
}, false);
el.textContent = " ";
el.style.height = 400+"px";
el.style.border = "1px solid red";
el.style.margin = 100+"px";
document.body.appendChild(el);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krll-k, 2015-09-11
@krll-k

And what's the problem, you take the first value as 0, and you calculate from it. True, the touchmove will be updated even if you go beyond the element. But you can decide by touch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question