From 9a4c0c7eb9bf6b50ff55b720324a4dff967b6591 Mon Sep 17 00:00:00 2001 From: A Jordan Simonds Date: Mon, 15 Feb 2021 21:06:37 -0500 Subject: [PATCH] fix: Account for scroll change when transitioning helper --- src/ContainerMixin.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ContainerMixin.js b/src/ContainerMixin.js index 1c4f37e6..06cf1e18 100644 --- a/src/ContainerMixin.js +++ b/src/ContainerMixin.js @@ -463,9 +463,10 @@ export const ContainerMixin = { const indexNode = nodes[this.index].node; let targetX = 0; let targetY = 0; - const deltaScroll = { - left: this.scrollContainer.scrollLeft - this.initialScroll.left, - top: this.scrollContainer.scrollTop - this.initialScroll.top, + + const scrollDifference = { + top: window.pageYOffset - this.initialWindowScroll.top, + left: window.pageXOffset - this.initialWindowScroll.left, }; if (this.hub && !this.hub.isDest(this)) { @@ -481,10 +482,19 @@ export const ContainerMixin = { left: dest.scrollContainer.scrollLeft, top: dest.scrollContainer.scrollTop, }; - targetX = newIndexNode.offsetLeft - destScroll.left - (indexNode.offsetLeft - sourceScroll.left); - targetY = newIndexNode.offsetTop - destScroll.top - (indexNode.offsetTop - sourceScroll.top); + targetX = + newIndexNode.offsetLeft - + scrollDifference.left - + destScroll.left - + (indexNode.offsetLeft - sourceScroll.left); + targetY = + newIndexNode.offsetTop - scrollDifference.top - destScroll.top - (indexNode.offsetTop - sourceScroll.top); } else { const newIndexNode = nodes[this.newIndex].node; + const deltaScroll = { + left: this.scrollContainer.scrollLeft - this.initialScroll.left, + top: this.scrollContainer.scrollTop - this.initialScroll.top, + }; targetX = -deltaScroll.left; if (this.translate && this.translate.x > 0) { // Diff against right edge when moving to the right