Skip to content

Commit

Permalink
add prevent option
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed May 30, 2024
1 parent fe13f58 commit c305ac2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ function raf(time) {
requestAnimationFrame(raf)
```

Add the following CSS to your project:

```css
html.lenis, html.lenis body {
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-smooth iframe {
pointer-events: none;
}
```

### GSAP ScrollTrigger:
```js
const lenis = new Lenis()
Expand Down Expand Up @@ -170,31 +194,6 @@ See documentation for [lenis/react](https://github.com/darkroomengineering/lenis
|----------|--------------------|
| `scroll` | Lenis instance |

<br/>

## Recommended CSS

```css
html.lenis, html.lenis body {
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-smooth iframe {
pointer-events: none;
}
```

<br/>

Expand Down
9 changes: 7 additions & 2 deletions packages/core/playground/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ document.querySelector('#app').innerHTML = new LoremIpsum().generateParagraphs(
200
)

const lenis = new Lenis()
const lenis = new Lenis({
prevent: (node) => {
console.log(node)
return false
},
})
lenis.on('scroll', (e) => {
console.log(e.userData, e.velocity, e.isScrolling)
// console.log(e.userData, e.velocity, e.isScrolling)
})
window.lenis = lenis

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type LenisOptions = {
touchMultiplier?: number
wheelMultiplier?: number
autoResize?: boolean
prevent?: string[] | (node: Element) => boolean
__experimental__naiveDimensions?: boolean
}

Expand Down Expand Up @@ -75,6 +76,7 @@ export default class Lenis {
touchMultiplier = 1,
wheelMultiplier = 1,
autoResize = true,
prevent = false,
__experimental__naiveDimensions = false,
}: LenisOptions = {}) {
window.lenisVersion = version
Expand Down Expand Up @@ -102,6 +104,7 @@ export default class Lenis {
touchMultiplier,
wheelMultiplier,
autoResize,
prevent,
__experimental__naiveDimensions,
}

Expand Down Expand Up @@ -225,6 +228,7 @@ export default class Lenis {
if (
!!composedPath.find(
(node) =>
this.options.prevent(node) ||
node.hasAttribute?.('data-lenis-prevent') ||
(isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||
(isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||
Expand Down

0 comments on commit c305ac2

Please sign in to comment.