Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

What is the default value for the "scroller" property when using ScrollTrigger?

Recommended Posts

When creating a ScrollTrigger, I know that if I don't include the "scroller" property it will use the viewport, but I can alternatively give the id of an overflow scrolling element instead.


But if I wanted to make the scroller value conditional, what is the default property I should use to tell it to use the viewport?


For example:

scrollTrigger: {
  id: triggerId,
  scroller: (useOverflow ? '#my-overflow-id' : ''),
  trigger: '#trigger-1',
  start: 'top top',
  end: 'bottom top'

An empty string seems to work, but I don't know if that's by chance - I obviously don't want GSAP to be wasting resources trying to find elements in the DOM that don't exist.

Link to post
Share on other sites

Hey Alex. ScrollTrigger defaults to "the viewport" as you say so an invalid value like an empty string will work just fine (so long as that invalid value doesn't throw a JS error like the variable being undefined).

  • Like 1
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.