Created
July 24, 2019 19:22
-
-
Save davidlagace/04247f61df64040dc650579c40c1f3c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="js-position-sticky-bottom a-slide-from-bottom"> | |
| ... | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| }; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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