Another question from the Global Elementor Facebook Community.
The author wanted to start a Lottie animation when a parent container is hovered. Unfortunately, there is no such option.
This tutorial shows a way to do it by using JavaScript.
Another question from the Global Elementor Facebook Community.
The author wanted to start a Lottie animation when a parent container is hovered. Unfortunately, there is no such option.
This tutorial shows a way to do it by using JavaScript.
Add a Container to the Editor for the Lottie and other content. This could be a Column or a Flexbox container.
Add the JavaScript to the site. Copy the code below.
To put it on a Page, add an HTML Widget and paste it into there.
Alternately, use Elementor -> Custom Code, or any other plugin you use for custom JavaScript.
<script>
;( w => {
w.addEventListener('elementor/frontend/init', () => {
elementorFrontend.hooks.addAction('frontend/element_ready/lottie.default', $scope => {
if ($scope.hasClass('trigger-on-parent-hover')) {
setTimeout(() => {
initListener();
}, 300);
}
const initListener = () => {
const lottie = $scope.find('.e-lottie__animation').data('lottie');
const parent = $scope.parent();
lottie.setDirection(1);
lottie.stop();
w.lottie = lottie;
parent.hover(
() => {
console.info('PLAY LOTTIE');
lottie.setDirection(1);
lottie.setSpeed(1);
lottie.play();
},
() => {
console.info('REVERSE LOTTIE');
lottie.setDirection(-1);
lottie.setSpeed(2);
lottie.play();
}
)
}
});
})
})(window)
</script>