A Pen by Leo Seyers on CodePen.
Created
May 10, 2019 00:52
-
-
Save git2358/0fb6b7b964b9700336829dc80cfbed0f to your computer and use it in GitHub Desktop.
Delayed Momentum Scroll
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
| <body :style="getPageHeight"> | |
| <div id="app"> | |
| <div class="content"> | |
| <div class="txt"> | |
| <p v-for="item in 8" :key="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque fuga corporis laboriosam voluptatum cupiditate blanditiis maiores voluptatem quo inventore, nemo culpa! Eum illum tenetur sequi, nostrum sed quia eius iste?</p> | |
| </div> | |
| </div> | |
| </div> | |
| </body> |
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
| // Replicate from https://benmingo.com | |
| // next step : try using vue-motion | |
| new Vue({ | |
| el: "#app", | |
| data() { | |
| return { | |
| positionY: 0, | |
| ratio: 1, | |
| pageHeight: null, | |
| elements: [] | |
| }; | |
| }, | |
| computed: { | |
| computedPosition() { | |
| return { | |
| transform: `translate3D(0, -${this.positionY}px, 0)` | |
| }; | |
| }, | |
| getPageHeight() { | |
| return { | |
| height: `${this.pageHeight}px` | |
| }; | |
| } | |
| }, | |
| mounted() { | |
| var content = document.querySelector(".txt"); | |
| var rect = content.getBoundingClientRect(); | |
| this.pageHeight = rect.height - window.innerHeight; | |
| this.support = this.getSupport(); | |
| if (this.support.isFirefox) { | |
| this.ratio = 15; | |
| } | |
| this.elements = document.querySelectorAll("p"); | |
| document.onwheel = e => { | |
| this.positionY = this.clamp( | |
| this.positionY + e.deltaY * this.ratio, | |
| 0, | |
| this.pageHeight | |
| ); | |
| this.animateElements(); | |
| }; | |
| }, | |
| methods: { | |
| getSupport() { | |
| return { | |
| isFirefox: navigator.userAgent.indexOf("Firefox") > -1 | |
| }; | |
| }, | |
| clamp(value, min, max) { | |
| return Math.min(Math.max(min, value), max); | |
| }, | |
| animateElements() { | |
| this.elements.forEach((el, i) => { | |
| TweenMax.to(el, 0.7, { | |
| y: -this.positionY, | |
| opacity: 1, | |
| delay: i * 0.02, | |
| ease: Expo.easeOut | |
| }); | |
| }); | |
| } | |
| } | |
| }); |
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
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.1/TweenMax.min.js"></script> |
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
| #app { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| bottom: 0; | |
| right: 0; | |
| pointer-events: none; | |
| background-color: #141414; | |
| color: white; | |
| font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif; | |
| } | |
| .content { | |
| position: relative; | |
| pointer-events: none; | |
| } | |
| p { | |
| padding-bottom: 2rem; | |
| } | |
| .txt { | |
| position: relative; | |
| padding: 50px; | |
| padding: 41.14286vh 0 28.57143vh 51.25vw; | |
| width: 36.08333vw; | |
| font-size: 1.66667vw; | |
| line-height: 2.16667vw; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment