Jump to content
Search Community

Draggable snap to selector

gaggo test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi there, just got a club license to use the amazing ThrowPropsPlugin in combination with `draggable` and `type`:`scroll`. Now I would very much like an option to make the scrolling snap to certain elements, if flicked. Is there an option or approach for this? 

Link to comment
Share on other sites

Hi @gaggo :)

 

With the scrollTo plugin, you can scroll to an element ID, but the snap is going to need a number. If all the elements are the same size, it would be pretty easy to use a function and snap to a value, but I'm assuming the elements won't be the same size. I think a fairly easy approach would be to loop through your elements and get their offsetTop distance and create your snap array from those values. Maybe something like this?

 

See the Pen KRBWeG by PointC (@PointC) on CodePen

 

Others may have additional suggestions, but that's the first thing that came to my mind. Happy tweening.

:)

 

 

  • Like 5
Link to comment
Share on other sites

Hi Craig, ok thank you, I think in this case I will have to write a callback function for the snap property and determine which element is closest to the value. Thanks again for your hints!

  • Like 1
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.
×
×
  • Create New...