{"id":38914511,"url":"https://github.com/phucbm/responsive-gsap","last_synced_at":"2026-01-17T15:24:42.434Z","repository":{"id":322761259,"uuid":"1090740032","full_name":"phucbm/responsive-gsap","owner":"phucbm","description":"A React hook that extends useGSAP with responsive media queries, resize observation, and load-controlled playback.","archived":false,"fork":false,"pushed_at":"2025-11-14T23:05:40.000Z","size":206,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-15T21:06:38.097Z","etag":null,"topics":["gsap","react","react-hooks","responsive","usegsap"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phucbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"phucbm","patreon":"phucbm","open_collective":"phucbm","ko_fi":"phucbm","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2025-11-06T04:28:59.000Z","updated_at":"2025-11-10T09:31:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c305ec4-9d10-4672-918d-ae77d0fa7c15","html_url":"https://github.com/phucbm/responsive-gsap","commit_stats":null,"previous_names":["phucbm/responsive-gsap"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/phucbm/responsive-gsap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fresponsive-gsap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fresponsive-gsap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fresponsive-gsap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fresponsive-gsap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phucbm","download_url":"https://codeload.github.com/phucbm/responsive-gsap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucbm%2Fresponsive-gsap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28511415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gsap","react","react-hooks","responsive","usegsap"],"created_at":"2026-01-17T15:24:41.697Z","updated_at":"2026-01-17T15:24:42.352Z","avatar_url":"https://github.com/phucbm.png","language":"TypeScript","funding_links":["https://github.com/sponsors/phucbm","https://patreon.com/phucbm","https://opencollective.com/phucbm","https://ko-fi.com/phucbm"],"categories":[],"sub_categories":[],"readme":"# useGSAPResponsive\n\n[![npm version](https://badgen.net/npm/v/responsive-gsap?icon=npm)](https://www.npmjs.com/package/responsive-gsap)\n[![npm downloads](https://badgen.net/npm/dm/responsive-gsap?icon=npm)](https://www.npmjs.com/package/responsive-gsap)\n[![npm dependents](https://badgen.net/npm/dependents/responsive-gsap?icon=npm)](https://www.npmjs.com/package/responsive-gsap)\n[![github stars](https://badgen.net/github/stars/phucbm/responsive-gsap?icon=github)](https://github.com/phucbm/responsive-gsap/)\n[![github license](https://badgen.net/github/license/phucbm/responsive-gsap?icon=github)](https://github.com/phucbm/responsive-gsap/blob/main/LICENSE)\n\nA thin, powerful wrapper around [`useGSAP`](https://gsap.com/resources/React/#usegsap-hook-) that adds **responsive setup**, **automatic re-initialization**, and **optional “play after load” control** — all while maintaining full compatibility with `useGSAP` best practices and return values.\n\n## ✨ Features\n\n* **Drop-in replacement for `useGSAP`** — returns the same value and integrates seamlessly.\n* **Responsive animation setups** via media queries (`gsap.matchMedia`).\n* **Auto re-setup on resize** — re-runs your animation setup when specific elements change size.\n* **Play-after-load control** — delay animation playback until page loading is complete.\n* **Safe cleanup** — guarantees proper `useGSAP` cleanup for timelines, matchMedia, and observers.\n* **Debug mode** — optional console logs for setup, cleanup, and media triggers.\n\n## Installation\n```bash\nnpm i responsive-gsap\n```\n```bash\npnpm add responsive-gsap\n```\n\n## 🚀 Usage\n\n### 1. Single setup\n\nFor simple, non-responsive animations:\n\n```tsx\nimport {useGSAPResponsive} from \"responsive-gsap\";\nimport gsap from \"gsap\";\nimport {useRef} from \"react\";\n\nexport function Example() {\n    const scope = useRef\u003cHTMLDivElement\u003e(null);\n\n    useGSAPResponsive((root) =\u003e {\n        const tl = gsap.timeline().from(root.querySelector(\".box\"), {x: -100, opacity: 0});\n        return {timeline: tl};\n    }, {scope});\n\n    return (\n        \u003cdiv ref={scope}\u003e\n            \u003cdiv className=\"box\"/\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n---\n\n### 2. Responsive setups (media queries)\n\nRun different animations per breakpoint with `mediaQueries`:\n\n```tsx\nimport {useGSAPResponsive} from \"responsive-gsap\";\nimport gsap from \"gsap\";\nimport {useRef} from \"react\";\n\nexport function Example() {\n    const scope = useRef\u003cHTMLDivElement\u003e(null);\n\n    useGSAPResponsive([\n        {\n            query: \"(max-width: 768px)\",\n            setup: (root) =\u003e ({\n                timeline: gsap.from(root.querySelector(\".box\"), {x: -50}),\n            }),\n        },\n        {\n            query: \"(min-width: 769px)\",\n            setup: (root) =\u003e ({\n                timeline: gsap.from(root.querySelector(\".box\"), {x: 100}),\n            }),\n        },\n    ], {scope});\n\n    return (\n        \u003cdiv ref={scope}\u003e\n            \u003cdiv className=\"box\"/\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\nEach setup cleans up automatically when the media condition changes.\n\n---\n\n### 3. Observe element resize\n\nRe-run animation setup when a target element’s size changes:\n\n```tsx\nimport {useGSAPResponsive} from \"responsive-gsap\";\nimport gsap from \"gsap\";\nimport {useRef} from \"react\";\n\nexport function Example() {\n    const scope = useRef\u003cHTMLDivElement\u003e(null);\n\n    useGSAPResponsive(\n        (root) =\u003e ({\n            timeline: gsap.from(root.querySelector(\".box\"), {scale: 0.5}),\n        }),\n        {\n            scope,\n            observeResize: \".box\",\n        }\n    );\n\n    return (\n        \u003cdiv ref={scope}\u003e\n            \u003cdiv className=\"box\"/\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\nUseful for dynamic layouts or fluid containers.\n\n---\n\n### 4. Play-after-load (deferred animation)\n\nPause animation until a loading process completes:\n\n```tsx\nimport {useGSAPResponsive} from \"responsive-gsap\";\nimport gsap from \"gsap\";\nimport {useRef} from \"react\";\n\nexport function Example() {\n    const scope = useRef\u003cHTMLDivElement\u003e(null);\n\n    const loadingHandlers = {\n        isLoadComplete: () =\u003e loadState === \"done\",\n        isLoadingEnabled: () =\u003e true,\n        onLoadComplete: (cb: () =\u003e void) =\u003e window.addEventListener(\"load\", cb),\n        offLoadComplete: (cb: () =\u003e void) =\u003e window.removeEventListener(\"load\", cb),\n    };\n\n    useGSAPResponsive(\n        (root) =\u003e ({\n            timeline: gsap.timeline().from(root.querySelector(\".box\"), {y: 50, opacity: 0}),\n        }),\n        {\n            scope,\n            playAfterLoad: loadingHandlers,\n        }\n    );\n\n    return (\n        \u003cdiv ref={scope}\u003e\n            \u003cdiv className=\"box\"/\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n---\n\n## 🧩 Notes\n\n* `useGSAPResponsive` **inherits all behavior from** `useGSAP`, including lifecycle and scope handling.\n* Always return `{ timeline, cleanup }` from your setup for best control.\n* Media query and resize-based setups clean up correctly without manual handling.\n\n---\n\n## 🧠 Example integration\n\nA responsive hero animation that waits for page load:\n\n```tsx\nimport {useGSAPResponsive} from \"responsive-gsap\";\nimport gsap from \"gsap\";\nimport {useRef} from \"react\";\n\nexport function Example() {\n    const scope = useRef\u003cHTMLDivElement\u003e(null);\n\n    const loadingHandlers = {\n        isLoadComplete: () =\u003e document.readyState === \"complete\",\n        isLoadingEnabled: () =\u003e true,\n        onLoadComplete: (cb: () =\u003e void) =\u003e window.addEventListener(\"load\", cb),\n        offLoadComplete: (cb: () =\u003e void) =\u003e window.removeEventListener(\"load\", cb),\n    };\n\n    useGSAPResponsive(\n        [\n            {\n                query: \"(max-width: 768px)\",\n                setup: (root) =\u003e ({\n                    timeline: gsap.from(root.querySelector(\".hero-title\"), {y: 40, opacity: 0}),\n                }),\n            },\n            {\n                query: \"(min-width: 769px)\",\n                setup: (root) =\u003e ({\n                    timeline: gsap.from(root.querySelector(\".hero-title\"), {x: -100, opacity: 0}),\n                }),\n            },\n        ],\n        {\n            scope,\n            playAfterLoad: loadingHandlers,\n            observeResize: \".hero-title\",\n            debug: true,\n        }\n    );\n\n    return (\n        \u003cdiv ref={scope}\u003e\n            \u003ch1 className=\"hero-title\"\u003eResponsive GSAP\u003c/h1\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n## License\nMIT © [phucbm](https://github.com/phucbm)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fresponsive-gsap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphucbm%2Fresponsive-gsap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucbm%2Fresponsive-gsap/lists"}