Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8679

anime.js スムーススクロール 実装方法

$
0
0

はじめに

初めてanime.jsでスムーススクロールの実装をしてみました。
普段はvelocity.jsを使っているため、やり方が違ってハマってしまい、調べても出てこなかったので備忘録として記事にしました。

実装方法

anime
//$target = document.querySelector(TARGET);scroll($target){const$window=window.document.scrollingElement||window.document.body||window.document.documentElement;anime({targets:{scroll:$window.scrollTop},scroll:$target.offsetTop,duration:500,easing:'easeInOutQuart',update:(a)=>{$window.scrollTop=a.animations[0].currentValue;}});}
velocity
//$target = document.querySelector(TARGET);scroll($target){velocity($target,'scroll');}

終わりに

他のアニメーションとの兼ね合いでanime.jsを使う必要がありました。
velocityのときは一行で済んでいたのですが、anime.jsだとそうもいかず。。
調べてもなかなか出てこず、ハマりました。
もう少しスマートにかけないかなあと思っているので、こうした方がいいよ等ございましたら
教えていただきたいです。


Viewing all articles
Browse latest Browse all 8679


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>