Jump to content
Search Community

Centering a div within a slider - Draggable

MaxiBartolozzi test
Moderator Tag

Recommended Posts

Hey Maxi and welcome to the GreenSock forums! Thanks for being a Club GreenSock member. 

 

There's a couple aspects of your approach that don't make much sense to me:

  • Your container element is scrollable. That completely ignores the draggable's effect, they don't play nicely with each other by default. I recommend preventing scrolling on your container.
  • You have an element called draggable but you apply the actual Draggable to the container... I'd apply the Draggable to the element called draggable.
  • You set the bounds to an element within the Draggable. The bounding element is presumed to be an element outside of the Draggable.

To set the default position of the draggle element, just set the x of it. Here's how I'd set it up. I included two different potential start positions because you weren't clear on the exact effect that you want.

See the Pen poJqqKy?editors=0010 by GreenSock (@GreenSock) on CodePen

 

For an even better effect, add in GSAP's IntertiaPlugin!

See the Pen OJVrrEY?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 3
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...