Capítulo 359 de 411

Chapter 359: ScrollTrigger.isInViewport

Core Idea

Returns true if the element is in the viewport. You can optionally specify a minimum proportion, like ScrollTrigger.isInViewport(element, 0.2) would only return true if at least 20% of the element is in the viewport.

Key Concepts

  • Element: Element | String

  • proportion: Number

  • horizontal: Boolean

Code Examples

// is any part of the element in the viewport?
if (ScrollTrigger.isInViewport(element)) {
  // you can use selector text
  // do stuff
}
  • What it demonstrates: typical usage of ScrollTrigger.isInViewport in a GSAP animation.

Key Takeaways

  1. Element: Element | String

  2. proportion: Number

  3. horizontal: Boolean

Connects To