Skip to content

Commit

Permalink
Fix autoScroll with containers with fixed position
Browse files Browse the repository at this point in the history
Closes #196
  • Loading branch information
taye committed Jun 14, 2015
1 parent 6a7ba46 commit 3635840
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,24 +696,36 @@
return rootNode.defaultView || rootNode.parentWindow || window;
}

function getElementRect (element) {
var scroll = isIOS7orLower
? { x: 0, y: 0 }
: getScrollXY(getWindow(element)),
clientRect = (element instanceof SVGElement)?
element.getBoundingClientRect():
element.getClientRects()[0];
function getElementClientRect (element) {
var clientRect = (element instanceof SVGElement
? element.getBoundingClientRect()
: element.getClientRects()[0]);

return clientRect && {
left : clientRect.left + scroll.x,
right : clientRect.right + scroll.x,
top : clientRect.top + scroll.y,
bottom: clientRect.bottom + scroll.y,
left : clientRect.left,
right : clientRect.right,
top : clientRect.top,
bottom: clientRect.bottom,
width : clientRect.width || clientRect.right - clientRect.left,
height: clientRect.heigh || clientRect.bottom - clientRect.top
};
}

function getElementRect (element) {
var clientRect = getElementClientRect(element);

if (!isIOS7orLower && clientRect) {
var scroll = getScrollXY(getWindow(element));

clientRect.left += scroll.x;
clientRect.right += scroll.x;
clientRect.top += scroll.y;
clientRect.bottom += scroll.y;
}

return clientRect;
}

function getTouchPair (event) {
var touches = [];

Expand Down Expand Up @@ -3111,7 +3123,7 @@
bottom = pointer.clientY > container.innerHeight - autoScroll.margin;
}
else {
var rect = getElementRect(container);
var rect = getElementClientRect(container);

left = pointer.clientX < rect.left + autoScroll.margin;
top = pointer.clientY < rect.top + autoScroll.margin;
Expand Down

0 comments on commit 3635840

Please sign in to comment.