Skip to content

Commit

Permalink
fix: add scroll offset
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Sep 6, 2015
1 parent 16707f5 commit 7b36fb6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/nipplejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ u.prepareEvent = function (evt) {
return isTouch ? evt.touches[0] : evt;
};

u.getScroll = function () {
var x = (window.pageXOffset !== undefined) ?
window.pageXOffset :
(document.documentElement || document.body.parentNode || document.body)
.scrollLeft;

var y = (window.pageYOffset !== undefined) ?
window.pageYOffset :
(document.documentElement || document.body.parentNode || document.body)
.scrollTop;
return {
x: x,
y: y
};
};

///////////////////////
/// THE NIPPLE ///
///////////////////////
Expand Down Expand Up @@ -336,15 +352,16 @@ Nipple.prototype.computeDirection = function (evt, obj) {

Nipple.prototype.onstart = function (evt) {
evt = u.prepareEvent(evt);
var scroll = u.getScroll();
this.box = this.options.zone.getBoundingClientRect();
this.pos = {
x: evt.pageX,
y: evt.pageY
};

this.backPos = {
x: this.pos.x - (this.box.left + this.options.size / 2),
y: this.pos.y - (this.box.top + this.options.size / 2)
x: this.pos.x - (scroll.x + this.box.x + this.options.size / 2),
y: this.pos.y - (scroll.y + this.box.y + this.options.size / 2)
};

this.bindEvt(document, 'move')
Expand Down

0 comments on commit 7b36fb6

Please sign in to comment.