GSAP matchMedia
Utility
Responsive
GSAP
JS
- Run GSAP code only for certain screen sizes
<script>
document.addEventListener("DOMContentLoaded", () => {
// only on the desktop breakpoint
gsap.matchMedia().add("(min-width: 992px)", () => {
// your gsap timeline here
});
});
</script>- Run GSAP code with multiple breakpoints
<script>
document.addEventListener("DOMContentLoaded", () => {
let mm = gsap.matchMedia();
// on desktop
mm.add("(min-width: 992px)", () => {
// your gsap timeline here
return () => {
// optional: clean up non-gsap code when leaving this breakpoint
};
});
// on tablet and below
mm.add("(max-width: 991px)", () => {
// your gsap timeline here
});
// on tablet only
mm.add("(max-width: 991px) and (min-width: 768px)", () => {
// your gsap timeline here
});
});
</script>Preview Links
Custom JS
Enable custom code in preview or view on published site.
Enable custom code?
Last Updated: Dec 3, 2025
- Run GSAP code only for certain screen sizes
<script>
document.addEventListener("DOMContentLoaded", () => {
// only on the desktop breakpoint
gsap.matchMedia().add("(min-width: 992px)", () => {
// your gsap timeline here
});
});
</script>- Run GSAP code with multiple breakpoints
<script>
document.addEventListener("DOMContentLoaded", () => {
let mm = gsap.matchMedia();
// on desktop
mm.add("(min-width: 992px)", () => {
// your gsap timeline here
return () => {
// optional: clean up non-gsap code when leaving this breakpoint
};
});
// on tablet and below
mm.add("(max-width: 991px)", () => {
// your gsap timeline here
});
// on tablet only
mm.add("(max-width: 991px) and (min-width: 768px)", () => {
// your gsap timeline here
});
});
</script>