Jump to content
Search Community

GSAP + Astro

VecchiaPrugna test
Moderator Tag

Recommended Posts

What's the best way to integrate GSAP in a Astro project?
Here's what I did:

In my Layout.astro file I added a <script> where I perform the GSAP import

<script>
  import { gsap } from 'gsap';
</script>

However, If i try to use gsap in let's say index.astro (which uses Layout.astro) i get the a console error "gsap is not defined"

Why? How to make GSAP globally available in all pages, componenets etc

Link to comment
Share on other sites

I have zero experience with Astro, so you might want to ask that community but I bet it'd be easiest for you to just load the minified file like: 

<script src="https://cdn.jsdelivr.net/npm/gsap@3.12/dist/gsap.min.js"></script>

And then after that, you can use GSAP in a <script> tag. It's probably best to only run your code after the page loads, like:  

<script>
window.addEventListener("load", () => {
  gsap.to(...);
});
</script>

Or listen for a DOMContentLoaded event if you prefer not to have to wait until images load, for example. 

 

I hope that helps!

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...