使用Hammer.js获取点击位置在元素中的相对坐标

118

https://github.com/hammerjs/hammer.js/issues/572

var bb = e.target.getBoundingClientRect();
// Correct, but will not work with touch.
var position = {
    x: e.pointers[0].layerX,
    y: e.pointers[0].layerY,
}
// Correct and works with touch.
var position2 = {
    x: e.center.x - bb.left,
    y: e.center.y - bb.top,
}

 

留下一个答复

Please enter your comment!
Please enter your name here