LoginSignup
4
0

lenis.jsでposition:fixed要素のoverflow:scrollを効かせる

Last updated at Posted at 2024-01-26

はじめに

慣性スクロールを手軽に実装できる、Lenis.jsを使っているサイトでモーダルを作成した際、position:fixed要素のoverflow:scrollが効かない時の対処法です。

解決方法

1. スクロール要素に onwheel="event.stopPropagation()"を追加

<div class="fixed" onwheel="event.stopPropagation()">

2. jsでwheelイベント伝播を停止

const modal = document.querySelector('#cc-main')
modal.addEventListener('wheel',(e)=>{
  e.stopPropagation()
})

をjsに追加すれば解決します。

参考元

https://github.com/studio-freight/lenis/issues/14

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0