Skip to content

Instantly share code, notes, and snippets.

@Phongtlam
Last active November 23, 2020 03:18
Show Gist options
  • Save Phongtlam/b8bd55fdcd1a0fa77f52210e3e149a76 to your computer and use it in GitHub Desktop.
Save Phongtlam/b8bd55fdcd1a0fa77f52210e3e149a76 to your computer and use it in GitHub Desktop.
adjustPaddings
const adjustPaddings = isScrollDown => {
const container = document.querySelector(".cat-list");
const currentPaddingTop = getNumFromStyle(container.style.paddingTop);
const currentPaddingBottom = getNumFromStyle(container.style.paddingBottom);
const remPaddingsVal = 170 * (listSize / 2);
if (isScrollDown) {
container.style.paddingTop = currentPaddingTop + remPaddingsVal + "px";
container.style.paddingBottom = currentPaddingBottom === 0 ? "0px" : currentPaddingBottom - remPaddingsVal + "px";
} else {
container.style.paddingBottom = currentPaddingBottom + remPaddingsVal + "px";
container.style.paddingTop = currentPaddingTop === 0 ? "0px" : currentPaddingTop - remPaddingsVal + "px";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment