Back to all resources
GSAP
ScrollTrigger
web animation
scroll-based animation

Basic scrollTrigger setup

By Digipop
This code snippet uses the GSAP library to animate elements on a webpage based on the scroll position. The animation targets elements with the class .target and is controlled by the scroll position relative to another element with the class .trigger.

Parameters:
  • trigger: Specifies the element that triggers the start and end of the animation. Here, it is an element with the class .trigger.
  • start: Defines when the animation should start. In this case, it starts when the top of the .trigger element is 75% from the top of the viewport.
  • end: Defines when the animation should end. It ends when the bottom of the .trigger element is 25% from the top of the viewport.
  • toggleActions: Controls the actions taken at the start, end, and during the scroll. The actions are "play none none reverse", meaning the animation will play forward when the scroll trigger starts, and reverse when scrolling back past the start.
  • scrub: If set to a numerical value, it smooths out the animation transitions to correlate with the scroll position, making the animation scrub with the scroll. Here, it is set to 1, indicating true with smoothing.

Animation Properties:
  • property: Represents the CSS properties you want to animate. Replace property with the actual CSS property name (e.g., opacity, x, scale).
  • value: The target value for the CSS property specified. This should be replaced with the desired end value for the animation.

This setup is useful for creating engaging scroll-driven animations that activate when the user scrolls to specific parts of the page.