Skip to content

Commit

Permalink
Merge pull request #120 from mpkorstanje/patch-3
Browse files Browse the repository at this point in the history
Fix Mouse position in canvas with padding
  • Loading branch information
Alessandro Reinoso committed Jun 5, 2014
2 parents 27cd733 + 3540953 commit 9b1aed7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/quintus_input.js
Expand Up @@ -566,11 +566,18 @@ Quintus.Input = function(Q) {
e.preventDefault();
var touch = e.touches ? e.touches[0] : e;
var el = Q.el,
posX = touch.offsetX,
posY = touch.offsetY,
eX, eY,
stage = Q.stage(stageNum);
rect = el.getBoundingClientRect(),
style = window.getComputedStyle(el),
posX = touch.clientX - rect.left - parseInt(style.paddingLeft),
posY = touch.clientY - rect.top - parseInt(style.paddingTop);

var stage = Q.stage(stageNum);

if(Q._isUndefined(posX) || Q._isUndefined(posY)) {
posX = touch.offsetX;
posY = touch.offsetY;
}

if(Q._isUndefined(posX) || Q._isUndefined(posY)) {
posX = touch.layerX;
posY = touch.layerY;
Expand Down

0 comments on commit 9b1aed7

Please sign in to comment.