Jump to content
GreenSock

Thomas Günther

Limit Observer to pointer

Moderator Tag
Go to solution Solved by GreenSock,

Recommended Posts

Heya 👋

 

I noticed I can not limit an Observer to type: pointer. It will always trigger, also on mobile/touch devices.

 

While I can use a condition like e.event.type.includes('pointer') I'm wondering if this is a bug.

 

In this codepen I listen to onLeft and onRight but I don't want this on mobile devices. It will scroll, jump back and then animate the scroll.

See the Pen qBxMVmB by medienbaecker (@medienbaecker) on CodePen

Link to comment
Share on other sites

  • Solution

Great catch, @Thomas Günther. Sorry about the confusion there. That's fixed in the next release, but for now it should be as simple as wrapping your .observe() in this:

if (ScrollTrigger.isTouch !== 1) { // <- skip if it's a touch-only device
  ScrollTrigger.observe({
    type: "pointer",
    ...
  });
}

 

 

 

  • Like 1
Link to comment
Share on other sites

Thanks for the quick answer, @GreenSock! I'm glad you could fix it 👍

 

In the meantime the isTouch is also a much better solution than my event type condition, thanks!

Link to comment
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.
×