Created
March 27, 2024 06:34
-
-
Save vandanojan/a74a26edbb1ac7b4825b03fcafd3c12e to your computer and use it in GitHub Desktop.
To set a Lottie json file as background in Elementor Section/Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
First, create an Elementor section/container and set its CSS id as #lottie. | |
Then, add an HTML block below it and copy/paste the following code. | |
Upload your Lottie JSON file to the WordPress library and replace "path-to-lottie-file" in the code with the file URL. | |
--> | |
<style> | |
#lottie { | |
position: relative; | |
} | |
.lottie-background { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
} | |
</style> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.12.2/lottie_light.min.js"></script> | |
<script> | |
jQuery(document).ready(function($) { | |
function setLottieBackground($container, lottieUrl) { | |
var $lottieBackground = $('<div class="lottie-background"></div>'); | |
$container.prepend($lottieBackground); | |
var animation = bodymovin.loadAnimation({ | |
container: $lottieBackground.get(0), | |
renderer: 'svg', | |
loop: true, | |
autoplay: true, | |
path: lottieUrl | |
}); | |
} | |
// Set Lottie background for an Elementor section/container | |
var $container = $('#lottie'); | |
var lottieUrl = 'path-to-lottie-file'; //Replace this with your file URL | |
if (lottieUrl && $container.length) { | |
setLottieBackground($container, lottieUrl); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment