Jump to content
Search Community

Drag bounds move as image is dragged

dxc 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

Check out the Codepen and you'll notice that you're able to drag the octopus to the left a bit before the bounds stop you from going further. You can't go to the right at all. After you let go, you'd expect to be able to drag it to the right (back to where it started), but it seems as though the bounds reset based on the image's relative position. When you drag it, you can't go to the right, but you can go further to the left than you originally could. 


Thanks for your help! 

See the Pen QwLVzM by anon (@anon) on CodePen

Link to comment
Share on other sites

hmmm, it looks like you are getting a fairly small bounds rectangle

try logging it


gives me:


Object {top: -168, left: -87.79998779296875, width: 87.79998779296875, height: 168} 

Are those the values you are expecting?


That's what is being passed into Draggable.


Try to create the bounds object with hard-coded values and see if it works as expected.

Link to comment
Share on other sites

I thought it might have something to do with Snap or calling the node, but even if you take snap out of the equation, the same thing happens: 

Draggable.create($("#geometricOctopus2"), {type:"x,y", bounds:bounds});
Link to comment
Share on other sites

  • 1 month later...


Hi dxc  :)


you can define specific maximum and minimum values ;

pls try this :

	var bounds = {
		minY:windowSize.y - svgRect.height, 
		minX:windowSize.x - svgRect.width, 
		maxX:svgRect.width  - windowSize.x,
		maxY:svgRect.height  - windowSize.y,

Thanks @Diaco.AW , that worked like a charm!

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