In the Skill's Own Terms
Official GSAP guidance for animating Vue, Nuxt, Svelte and SvelteKit components, where the framework lifecycle decides when DOM nodes exist. It tells the agent to create tweens and ScrollTriggers only after mount — onMounted in Vue, onMount in Svelte — inside gsap.context(scope) with the container ref passed as the second argument, so selectors like .box stay inside that component.
On unmount, ctx.revert() kills the animations and ScrollTriggers and reverts inline styles. It also covers a Nuxt 4 useGSAP composable that registers ScrollTrigger once and lazy loads plugins such as SplitText by dynamic import, plus refreshing trigger positions after layout changes.
What it produces
- A runnable Vite + Vue 3 example project demonstrating the context and cleanup patterns.
- A Nuxt composable, consumed in components through useGSAP(), that exposes the gsap instance and the lazy loading method.
- A typed lazyLoadPlugin helper that dynamically imports a plugin, registers it with gsap and returns it.
How It Works
- 01Wait for the DOM Before Creating
Tweens and ScrollTriggers are only created once the component's DOM is available, using onMounted in Vue or onMount in Svelte so the container ref actually exists.
- 02Scope Everything to the Component Root
The whole animation setup is wrapped in gsap.context(callback, scope), with the container ref passed as the second argument so selectors such as .item resolve inside that subtree only.
- 03Revert in the Framework Teardown
Each example keeps the context in a variable and calls ctx.revert() from onUnmounted (Vue) or from the cleanup function returned by onMount (Svelte).
- 04Refresh After Layout Changes
ScrollTrigger positions are recalculated once the layout settles, for example after data loads change trigger positions.