0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

慣性スクロールライブラリ Lenis

Last updated at Posted at 2023-05-08

official

https://lenis.studiofreight.com/
https://github.com/darkroomengineering/lenis

npm package

$ npm i lenis

usage

import Lenis from 'lenis'

interface Window {
  lenis: Lenis;
}

const lenis = new Lenis({
  lerp: 0.1,
  duration: 1.0,
  easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
  orientation: 'vertical',
  gestureOrientation: 'vertical',
  smoothWheel: true,
  smoothTouch: false,
  touchMultiplier: 2,
});

function raf(time) {
  lenis.raf(time);
  requestAnimationFrame(raf);
}

requestAnimationFrame(raf);

window.lenis = lenis;

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  anchor.addEventListener('click', (e) => {
    e.preventDefault();
    window.lenis.scrollTo(anchor.getAttribute('href'), {
      duration: 0.4,
    })
  });
});

スクロールバーを表示(機能)させたい要素に属性を指定

<div data-lenis-prevent></div>
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?