Good morning to everyone, i’m just learning how to implement external js to bricks.
So i made an example and if i add this code in the code elements it works:
So i get the gsap library from cdn link and i add a simple gsap animation to an image with a specific class.
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script>
<script>
gsap.to(".lago2", {duration: 2, x: 200, ease: "bounce"});
</script>
<style>
.lago2 {
width:180px;
}
</style>
i discovered that it’s better to add the js libraries with enqueue in function.php
So i tried to add to the function.php child-theme this code:
function wpb_adding_scripts(){
wp_register_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js', array(), '1.0', true );
wp_enqueue_script('gsap');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
and i remove from the code elements in bricks the script src about the cdn link.
So my code in the bricks code element it’s like this:
<script>
gsap.to(".lago2", {duration: 2, x: 200, ease: "bounce"});
</script>
<style>
.lago2 {
width:180px;
}
</style>
But it doesn’t work…what it’s wrong? could you help me to understand how to make it?
Thanks
Davide