Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs from previous patch #229

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/bodyScrollLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,10 @@ const setPositionFixed = () => window.requestAnimationFrame(() => {
};

// Update the dom inside an animation frame
const { scrollY, scrollX, innerHeight } = window;
const { scrollY, scrollX } = window;
document.body.style.position = 'fixed';
document.body.style.top = -scrollY;
document.body.style.left = -scrollX;

setTimeout(() => window.requestAnimationFrame(() => {
// Attempt to check if the bottom bar appeared due to the position change
const bottomBarHeight = innerHeight - window.innerHeight;
if (bottomBarHeight && scrollY >= innerHeight) {
// Move the content further up so that the bottom bar doesn't hide it
document.body.style.top = -(scrollY + bottomBarHeight);
}
}), 300)
document.body.style.top = `${-scrollY}px`;
document.body.style.left = `${-scrollX}px`;
}
});

Expand All @@ -141,8 +132,8 @@ const restorePositionSetting = () => {

// Restore styles
document.body.style.position = previousBodyPosition.position;
document.body.style.top = previousBodyPosition.top;
document.body.style.left = previousBodyPosition.left;
document.body.style.top = `${previousBodyPosition.top}px`;
jvitela marked this conversation as resolved.
Show resolved Hide resolved
document.body.style.left = `${previousBodyPosition.left}px`;

// Restore scroll
window.scrollTo(x, y);
Expand Down