Skip to content

Instantly share code, notes, and snippets.

@davidlagace
Created July 24, 2019 19:22
Show Gist options
  • Select an option

  • Save davidlagace/04247f61df64040dc650579c40c1f3c9 to your computer and use it in GitHub Desktop.

Select an option

Save davidlagace/04247f61df64040dc650579c40c1f3c9 to your computer and use it in GitHub Desktop.
<div class="js-position-sticky-bottom a-slide-from-bottom">
...
</div>
import $ from 'jquery';
$(function () {
let stickyNavBottom = {
elem: document.querySelector(".js-position-sticky-bottom"),
data:{},
offsetTop:0,
get height() {
return this.elem.getBoundingClientRect().height || 0;
}
};
// Functions
// ------------------------------------------
const updateStickyNavState = () => {
window.removeEventListener("scroll", updateStickyNavState);
if ((window.scrollY + window.innerHeight) >= (stickyNavBottom.offsetTop + stickyNavBottom.height)) {
stickyNavBottom.elem.classList.remove('fixed-bottom', 'vui-anim--slide-from-bottom');
} else {
stickyNavBottom.elem.classList.add('fixed-bottom');
}
window.addEventListener("scroll", updateStickyNavState);
};
const initStickyNav = () => {
stickyNavBottom.data = stickyNavBottom.elem.getBoundingClientRect();
stickyNavBottom.offsetTop = Math.ceil(stickyNavBottom.data.top) + window.pageYOffset;
updateStickyNavState();
};
window.onload = () => {
if (typeof stickyNavBottom.elem !== "undefined" && stickyNavBottom.elem) {
initStickyNav();
}
};
});
@keyframes slide-from-bottom {
from {transform: translate(0,100%);}
}
/* ***************************************************************************** */
.a {
&-slide-from-bottom {
will-change: transform, opacity;
&.fixed-bottom {
animation: slide-from-bottom all .2s ease-in-out;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment