Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/smoothscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
return el;
}

var lastStartX,
lastStartY,
lastCurrentX,
lastCurrentY;
/**
* self invoked function that, given a context, steps through scrolling
* @method step
Expand All @@ -122,10 +126,42 @@
currentX = context.startX + (context.x - context.startX) * value;
currentY = context.startY + (context.y - context.startY) * value;

//The user, or some other system, scrolled mid scroll.
if(typeof lastCurrentX != "undefined" &&
typeof lastCurrentY != "undefined" &&
( document.body.scrollTop !== Math.floor(lastCurrentY)
|| document.body.scrollLeft !== Math.floor(lastCurrentX))){
lastStartX = undefined;
lastStartY = undefined;
lastCurrentX = undefined;
lastCurrentY = undefined;
w.cancelAnimationFrame(context.frame);
return;
}

//The user, or some other system, scrolled before the scroll began.
if(typeof lastStartX != "undefined" && typeof lastStartY != "undefined" && (context.startX !== lastStartX || context.startY !== lastStartY)){
lastStartX = undefined;
lastStartY = undefined;
lastCurrentX = undefined;
lastCurrentY = undefined;
w.cancelAnimationFrame(context.frame);
return;
}

context.method.call(context.scrollable, currentX, currentY);

lastStartX = context.startX;
lastStartY = context.startY;
lastCurrentX = currentX;
lastCurrentY = currentY

// return when end points have been reached
if (currentX === context.x && currentY === context.y) {
lastStartX = undefined;
lastStartY = undefined;
lastCurrentX = undefined;
lastCurrentY = undefined;
w.cancelAnimationFrame(context.frame);
return;
}
Expand Down