Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
dxc

Drag bounds move as image is dragged

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

console.log(bounds)

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

Though bounds size reacts slightly differently when I put in hard-coded numbers (codepen updated), but the bounds still move every time you let go of the image. 

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

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,
	};
  • Like 1
Link to comment
Share on other sites

Works perfectly. Thanks!!! 

 

- Lance

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.

×