Skip to content

Instantly share code, notes, and snippets.

@GGrassiant
Last active February 23, 2021 22:43
Show Gist options
  • Select an option

  • Save GGrassiant/fb7533d5dd2b8eb2b1b78d92f683be35 to your computer and use it in GitHub Desktop.

Select an option

Save GGrassiant/fb7533d5dd2b8eb2b1b78d92f683be35 to your computer and use it in GitHub Desktop.
Sidebar adjustments

A. Sidebar Adjustments

.sidebar {
left: 0 !important;
display: none;
@media (min-width: $screen-md) {
display: block;
}
}
.articles-filters {
@extend .sidebar;
position: fixed;
transition: top 700ms ease-in-out;
}
// sideBar is position: fixed but if the footer covers it, move it up
// if not, set it back to its original position
const sideBar = document.querySelector('.articles-filters');
if (sideBar) {
const sideBarTopProperty = sideBar.offsetTop;
window.addEventListener('scroll', function (e) {
const sideBarHeight = sideBar.clientHeight;
const footerPosition = document
.querySelector('footer')
.getBoundingClientRect().y;
if (sideBarHeight > footerPosition) {
sideBar.style.top = `${
sideBarTopProperty - (sideBarHeight - footerPosition)
}px`;
} else {
sideBar.style.top = `${sideBarTopProperty}px`;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment