Jump to content
Search Community

Gsap Draggable Snap is not working!

Nihal test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi @Nihal and welcome to the GreenSock forums!

 

Snap is available on;y with the Inertia Plugin:

https://greensock.com/docs/v3/Plugins/InertiaPlugin

 

Out of the box Draggable has a Live Snap feature that works as you drag. The other option is to create your own custom logic in the onDragEnd callback, to create your own snapping function. Something like this:

Draggable.create(wheel, {
  allowContextMenu: true,
  type: "rotation",
  trigger: wheel,
  onDragEnd: function() {
    gsap.to(wheel, {
      rotation: gsap.utils.snap((360 / images.length), this.rotation)
    });
  },
  snap: {
    rotation: gsap.utils.snap(360 / images.length)
  }
});

Here is a fork of your codepen using this code:

See the Pen rNQmOvQ by GreenSock (@GreenSock) on CodePen

 

Hopefully this helps.

Happy Tweening!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hi @Rodrigo there is one bug in your code i can't seems to solve,  you see if we drag to left active class is added to the next slide but when i drag to right none of the items gets active class ( drag to right from woman's health card to vegan )

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

It can be done but is not the simplest thing to achieve:

See the Pen JjZdPWj by GreenSock (@GreenSock) on CodePen

 

Unfortunately we don't have the time resources to create custom solutions for our users. You can contact us for paid consulting or post in the Jobs & Freelance forum to get help there.

 

Good luck with your project!

Happy Tweening!

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...