Skip to content

Commit

Permalink
[SmoothScroll] Update scroll properties from lenis
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineW committed Feb 6, 2024
1 parent 58050ad commit ecf4cbe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/js/luge/core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,27 @@ class Luge {
* Scroll handler
*/
scrollHandler () {
window.scrollTop = window.scrollY

// Backward compatibility
window.unifiedScrollTop = window.scrollTop

if (!this.isScrolling) {
this.scrollStart()
}

clearTimeout(this.timeouts.scrollEnd)
this.timeouts.scrollEnd = setTimeout(this.scrollEnd.bind(this), 200)

if (!window.hasSmoothScroll) {
this.updateScroll()
}
}

/**
* Update scroll
*/
updateScroll () {
window.scrollTop = window.scrollY

// Backward compatibility
window.unifiedScrollTop = window.scrollTop

this.previousScrollTop = window.scrollTop
window.scrollProgress = window.scrollTop / window.maxScrollTop

Expand Down
6 changes: 5 additions & 1 deletion src/js/luge/plugins/SmoothScroll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Helpers from '../core/Helpers'
import Core from '../core/Core'
import Plugin from '../core/Plugin'

import Lenis from '@studio-freight/lenis'
Expand Down Expand Up @@ -30,6 +30,10 @@ export default class SmoothScroll extends Plugin {

this.lenis = new Lenis()

this.lenis.on('scroll', () => {
Core.updateScroll()
})

document.documentElement.classList.add('has-smooth-scroll')

this.luge.ticker.add(this.lenis.raf, this.lenis)
Expand Down
1 change: 1 addition & 0 deletions src/scss/luge.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import 'luge/easing';

@import 'luge/cursor';
@import 'luge/lenis';
@import 'luge/loader';
@import 'luge/preloader';
@import 'luge/reveal';
19 changes: 19 additions & 0 deletions src/scss/luge/_lenis.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
html.lenis {
height: auto;
}

.lenis.lenis-smooth {
scroll-behavior: auto !important;
}

.lenis.lenis-smooth [data-lenis-prevent] {
overscroll-behavior: contain;
}

.lenis.lenis-stopped {
overflow: hidden;
}

.lenis.lenis-scrolling iframe {
pointer-events: none;
}

0 comments on commit ecf4cbe

Please sign in to comment.