WebPublisher/JavaScript & jQuery
[lottie] lottie 라이브러리 활용해 data-type별로 다른 lottie 애니메이션 적용하기
amanda
2025. 6. 8. 21:26
<div class="lottie_wrap" data-type="type01">
<div id="lottie"></div>
</div>
setLottieAni();
function setLottieAni() {
const lottieContainer = document.getElementById('lottie');
const lottieWrap = lottieContainer.closest('.lottie_wrap');
if (!lottieWrap) return;
// data-type 속성값 읽기
const typeValue = lottieWrap.getAttribute('data-type');
if (!typeValue) {
console.warn('data-type 속성이 지정되지 않았습니다.');
return;
}
const animationPath = `./lottie_${typeValue}.json`;
// Lottie 애니메이션 로드
bodymovin.loadAnimation({
container: lottieContainer,
renderer: 'svg',
loop: true,
autoplay: true,
path: animationPath
});
}