javascript๐ช/์๋ฐ์คํฌ๋ฆฝํธ ๊ณต๋ถ
Animate.css ํ์ฉ fadeInํจ๊ณผ ๊ฑธ๊ธฐ
hyojinny
2023. 10. 23. 15:25
๊ธฐ์กด ์ ์ด์ฟผ๋ฆฌ๋ก fade - in, out ์ ๊ฑธ์๋ ๋ฐฉ๋ฒ๊ณผ๋ ๋ค๋ฅด๊ฒ , animate ์ฌ์ดํธ์ ๋์จ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํด ํจ๊ณผ์ฃผ๊ธฐ
text ๋ฅผ ํ์ด๋์ธ ์ผ๋ก ๋์ค๊ฒ ํ๋ค
์ ์ฉ๋ฐฉ๋ฒ์ 2๊ฐ์ง install ๋ก ์ค์นํ๊ฑฐ๋ CDN ๋ก ๋งํฌ์ฝ์
์์ฑ์ค์ธ html.index ํ์ผ์ link ํ๊ทธ๋ก CDN ๋ฐฉ์ ์ถ๊ฐ
์ฌ์ดํธ ์๋ด๋ฅผ ๋ณด๊ณ ์๋ฐ์คํฌ๋ฆฝ์๋ ์ ์ฉ
//ํ
์คํธ๋ฐ์ค ์๋๋ฉ์ด์
์ ์ฉ
const currentSlice = slides[currentIndex];
const textBox = currentSlice.querySelector('.text-box');
textBox.classList.add('animate__animated', 'animate__fadeIn');
//์ฌ๋ผ์ด๋๊ฐ ๋ค ๋์๊ฐ๋ฉด animate__fadeIn์ด ํ๋ฆฌ๊ธฐ ๋๋ฌธ์ remove์ค์ ์ผ๋ก ๋ค์ํจ๊ณผ์ ์ฉ
textBox.addEventListener('animationend', function () {
textBox.classList.remove('animate__animated', 'animate__fadeIn');
});
๊ธฐ์กด์ ์์ฑํ ์ฌ๋ผ์ด๋ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ์์ ์๋๋ฉ์ด์ ์ ์ ์ฉํด์ค๋ค.
๋จ ์ฌ๋ผ์ด๋๊ฐ ํ๋ฒ๋์๊ฐ๋ฉด ๋จ์ํ ์๋๋ฉ์ด์ ์ ์ฉํ๊ฒ์ด ํ๋ฆฌ๋ฏ๋ก
remove ๋ฅผ ๊ฑธ์ด์ฃผ์ด ์ฐ์๋ ์๋๋ฉ์ด์ ์ด ์ ์ฉ๋๊ฒ ํ๋ค
์์ฉ ํ์ด๋์ธ ์๊ฐ์ค์
//ํ์ด๋์ธ ์๊ฐ ์ค์
textBox.style.setProperty('--animate-duration', '3s');