Jump to content
Search Community

Boundary without Draggable?

JeffK test
Moderator Tag

Recommended Posts

You'll have to create some logic that looks at current x and y positions and limits the next next move if the += goes over that. Something like:

 if (currentXPosition + xMov > xBoundry) { 
   xMov = `+=${xBoundry - currentXPosition}` 
 } else { 
   xMove = `+=${moveUnit}` 
 }

or better yet, you could use the gsap clamp utility to keep your position within certain bounds: https://greensock.com/docs/v3/GSAP/UtilityMethods/clamp()  gsap.to(el, { x: gsap.utils.clamp(0, 900, currentPosition + moveUnit) })

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