ScrollReveal은 요소를 뷰포트에 enter / leave 할 때 요소를 쉽게 애니메이트하기위한 JavaScript 라이브러리이다.
직접 DOM을 Select 해서 스크롤 높이와 content의 높이를 계산해서 구현하려다 좋은 라이브러리가 있어서 사용하게 되었다.
사용 예시: https://wizball.io/info
Wizball(ウィズボール)の紹介ページ
WizballはLINK chain(ブロックチェーン)を基盤としたdAappとして運営する知識共有のためのQ&Aサービスです。
wizball.io
# 사용방법
1. vue-scroll-reveal 설치
yarn add vue-scroll-reveal
2. main.js에 vue-scroll-reveal 셋팅
import VueScrollReveal from 'vue-scroll-reveal';
Vue.use(VueScrollReveal);
3. 컴포넌트에 적용
mounted () {
this.$sr.reveal('.section', {
reset: true,
mobile: true,
beforeReveal: function (el) {
el.classList.add('animate');
},
beforeReset: function (el) {
el.classList.remove('animate');
}
});
}
# API
vue-scroll-reveal
https://www.npmjs.com/package/vue-scroll-reveal
vue-scroll-reveal
A Vue directive to wrap @jlmake's excellent ScrollReveal library.
www.npmjs.com
scroll-reveal
https://scrollrevealjs.org/api/reveal.html
Reveal — ScrollReveal
Reveal bound function Registers the target element(s) with ScrollReveal, generates animation styles, and attaches event listeners to manage when styles are applied. Signature function (target, options) TargetstringCSS selector, matching 1 or more elements.
scrollrevealjs.org
간단한 기능인데, 라이브러리를 사용해도 되나 싶었는데(애플리케이션이 무거워질 수 있으니깐..) 확실히 코드가 많이 간단해지기 때문에 사용하기로 했다.
'JavaScript > Vue.js' 카테고리의 다른 글
Parallax.js in Vue (0) | 2019.05.23 |
---|---|
SPA와 SSR의 장단점 그리고 Nuxt.js (0) | 2019.05.20 |
Vue.js의 $refs를 통하여 DOM에 접근하기 (0) | 2019.05.14 |
zero base 환경 설정 (0) | 2019.05.10 |