Index of every page on this site: llms.txt
All skills
johnpolacek avatar

/gsap-vanilla

@8ddf542
Run it yourself

Build or review animation on plain HTML/CSS/JavaScript sites: GSAP page intros/outros, component show/hide, scroll effects, cross-document View Transitions, bfcache, and fetch/swap navigation with Swup, Barba, or Taxi. Use for first-paint flashes or interrupted navigation, even when GSAP is unnamed. Also covers hidden-content recovery and first-load performance. Not for component frameworks or isolated GSAP API questions.

Use this Skill: https://skilld.dev/gh/johnpolacek/animaxxing-skills/gsap-vanilla

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesspa-navigation.md

≈1.9k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Same-document navigation

Read this only when the site fetches pages and swaps content without reloading the document.

Decide whether to own a router

A same-document router must intercept links, fetch and parse HTML, swap content, update the title and URL, handle back and forward, restore scroll, move focus, re-run page scripts, cancel stale requests, and announce route changes. Swup, Barba, and Taxi do all of that and expose hooks where GSAP fits. Prefer one unless the project already owns a router or the user asks for one.

With a library, everything below still applies. Map its leave and enter hooks to outro and intro, return the timeline's promise so the library waits, and keep the lock, the cover, and cleanup as described.

Page lifecycle

mount → initial state → intro → settled → outro → end state → unmount

  1. Outro. The link is intercepted and the outgoing content plays its outro on live DOM while the next page is fetched.
  2. End state. Outgoing targets finalize and completion runs once. Raise the cover over the route container.
  3. Unmount and mount. The router replaces the container's children with the parsed content, updates the title, and pushes the URL.
  4. Initial state. The new content is in the DOM, sized, and measured. Start values are written behind the cover.
  5. Intro. Lower the cover and play one timeline to settled.
  6. Settled. Clear temporary styles. CSS owns the page.

One navigation at a time. The first accepted destination wins through outro, fetch, swap, and cover. Release the lock when the intro starts, not when it ends, so a click mid-intro kills the intro and starts the outro from current values. Abort the in-flight fetch with an AbortController when a new destination is accepted.

A killed timeline never resolves its promise. Wrap await in a helper that also resolves on onInterrupt and returns whether the timeline completed.

Intercepting links

Listen on the document for clicks and resolve the closest a[href]. Leave native: modified clicks, non-primary buttons, other origins, target, download, mailto and tel, hash-only and same-location links, and links marked to opt out. Use pushState for accepted links and replaceState for links marked replace.

Where the Navigation API exists, one navigate listener with event.intercept({ handler }) covers link clicks, form submissions, and programmatic navigation, and reports navigationType. Keep the click path as the fallback for browsers without it.

Fetching and swapping

  • Fetch with an Accept: text/html header and parse with DOMParser. Take the route container's content, the title, and any body attributes such as data-page that pages differ on.
  • Scripts inside fetched HTML do not execute when inserted. Register page setups in one module keyed by data-page and call the matching one after the swap. Do not rely on inline page scripts.
  • Stylesheets some pages add must be loaded before those pages are revealed. Append the link and wait for its load event.
  • Keep one route container. Persistent chrome lives outside it and never reloads. Its state, timelines, and listeners survive navigation, which is the reason to go same-document at all.
  • Overlap old and new only inside a reserved wrapper so one box owns the geometry. Hold the container's height during the swap, or animate it between measured sizes on purpose.
  • Keep the cover inside the route container, not fixed to the viewport, unless the effect is a full-screen wipe on purpose.

History, scroll, and focus

  • Set history.scrollRestoration to manual and own it. On push, scroll to top or to the hash target after the swap. Save the scroll position in the history state before leaving so popstate can restore it after the swap, then refresh ScrollTrigger. manual also turns off the browser's restore for a reload or a back and forward into a fresh document, so restore from the saved state at boot too.
  • Back and forward never run an outro. On popstate the URL has already changed. Fetch, swap, and run initial state and intro only, or wrap the swap in document.startViewTransition so it is not a hard cut.
  • After the swap, move focus to the route container or its main heading if focus was on removed content or on body. Give the target tabindex="-1" and a focus style that fits the design.
  • Update document.title and announce the new page through a live region.
  • Do not transition to the current URL. Treat search-param changes as page changes only when they mean a different screen.

Smooth scrolling, curtains, and shared elements

One scroller per document means one per router lifetime: create it with the router, outside the route container, never in a page setup. Map Smooth scrolling onto the router's own steps: stop() as the outro starts, restore or reset the native position after the swap as above and then scrollTo(position, { immediate: true }), resize() once the page setup has created its triggers, start() at settled. A failed fetch falls back to location.assign; an aborted fetch that leaves the page current calls start() where it releases the lock. With Swup, Barba, or Taxi, put the same calls in the library's leave, content-replace, and enter hooks; read the installed version's hook list rather than memory, since names changed between majors. A same-page hash link is a scrollTo(hash), not a navigation.

A curtain from Transition archetypes is the one case for a fixed cover: it lives beside the route container in persistent chrome, cover() composes into the outro, the swap runs on its completion, and reveal() runs after start values are written on the new content, overlapping the intro. popstate never covers.

Capture a shared element with captureShared as the outro starts, keep the state in the router module keyed by destination, clear it when the navigation settles or is replaced, and playShared(state, target) after the swap once the target is measured and visible. The old node left with the swap, so nothing stale can match; pass the target anyway. Flip cannot cross a document load: a full-document site uses view-transition-name instead, see Combining with GSAP.

Cleanup on unmount

Before replacing the container's children:

  • Revert the page's GSAP context, which kills its tweens, triggers, and splits and clears their inline styles.
  • Remove listeners, observers, timers, and plugin instances the page created.
  • Undo anything the page changed outside its container: scroll locks, root attributes, theme, body classes.
  • Do not kill triggers globally. Chrome and the next page own theirs.

Combining with same-document View Transitions

document.startViewTransition(() => swap()) snapshots the old content, runs the swap, and animates to the new snapshot. Use it for history navigation and plain crossfades. The rules are the same as cross-document: one engine per element, GSAP intros after finished for touched elements, and ::view-transition { pointer-events: none }.

Cases to design for

  • Navigation requested mid-intro.
  • Two destinations clicked quickly.
  • A fetch that fails or returns something that is not HTML. Fall back to location.assign.
  • A slow fetch. The cover stays up; show a hint after a delay.
  • Back or forward with no outro.
  • A page that changes body classes, theme, or scroll lock.
  • A page setup that should run on every visit versus once per session.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts26d3 checks · Risk SAFE
  • Gen Agent Trust Hub26d

    The GSAP Vanilla skill provides comprehensive architectural guidance and implementation patterns for web animations. The analysis found no evidence of malicious code, prompt injection, data exfiltration, or other security vulnerabilities. The instructions follow industry best practices for performance, accessibility, and lifecycle management.

  • Socket26d

    No alerts

  • Snyk26d

    Risk: LOW · No issues

Signed by skilld at 8ddf542. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 weeks ago.

Activeupdated 4 weeks ago
Other metadata
metadata
{
  "short-description": "GSAP page and component lifecycles on plain HTML sites"
}

README badge

README badge for johnpolacek/animaxxing-skills/gsap-vanilla