Skip to content

Commit

Permalink
Fix offset bug when top-most body has margins/padding.
Browse files Browse the repository at this point in the history
References #56 - "improve the touch/pointer coordinates calculations".
  • Loading branch information
joseph committed Jan 27, 2012
1 parent 504cd9d commit b7fb937
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/events.js
Expand Up @@ -99,11 +99,11 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
var r;
if (elem.getBoundingClientRect) {
var er = elem.getBoundingClientRect();
var dr = document.body.getBoundingClientRect();
var dr = document.documentElement.getBoundingClientRect();
r = { left: er.left - dr.left, top: er.top - dr.top };
} else {
r = { left: elem.offsetLeft, top: elem.offsetTop }
while (elem = elem.parentNode) {
while (elem = elem.offsetParent) {
if (elem.offsetLeft || elem.offsetTop) {
r.left += elem.offsetLeft;
r.top += elem.offsetTop;
Expand Down
2 changes: 1 addition & 1 deletion test/tests.css
Expand Up @@ -15,7 +15,7 @@ h1 {

body.narrow {
max-width: 25em;
/*margin: 0 auto;*/
margin: 0 auto;
}

h1, h2, h3, p, li {
Expand Down

0 comments on commit b7fb937

Please sign in to comment.