ScrollTrigger .isTouch Property
-
Learn how to detect touch devices using ScrollTrigger
.isTouchand optimize scroll animations for mobile performance.
Introduction
Not all users scroll the same way.
-
Desktop users → mouse wheel / trackpad
-
Mobile users → touch gestures
GSAP ScrollTrigger provides
.isTouchto detect touch-based devices so you can adjust animations for better performance and UX.-
What is
.isTouch?.isTouchis a global ScrollTrigger property that tells whether the current device supports touch input.Returned Values
Value Meaning 0Non-touch device (desktop) 1Touch-only device (mobile) 2Hybrid device (touch + mouse)
Basic Syntax
if (ScrollTrigger.isTouch) {
console.log("Touch device detected");
}
Exact Value Check
console.log(ScrollTrigger.isTouch);
Disable Heavy Animations on Mobile
if (!ScrollTrigger.isTouch) {
gsap.to(".box", {
x: 300,
scrollTrigger: ".box"
});
}
Change Animation Behavior for Touch
gsap.to(".card", {
y: 100,
scrollTrigger: {
trigger: ".card",
scrub: ScrollTrigger.isTouch ? false : true
}
});
Reduce Pinning on Mobile
ScrollTrigger.create({
trigger: ".section",
pin: !ScrollTrigger.isTouch,
end: "+=300"
});
Note:
Where .isTouch is Commonly Used
| Use Case | Reason |
|---|---|
| Disable pin | Mobile scroll issues |
| Reduce scrub | Touch scrolling is jumpy |
| Simplify animation | Performance |
| UX optimization | Better feel on mobile |