Jump to content
GreenSock

Guest GRDC

Draggable SVG Element x,y Percentages

Go to solution Solved by Guest GRDC,

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

I'm attempting to allow dragging of SVG elements on the screen, and store their coordinates as percentages in case of screen resize.  Since the type: "x,y" draggable uses transform, I'm converting the number of transformed pixels at the end of the drag.  All seems to be working, except the svg element itself does not update its position once it is dropped.

 

Here's a codepen to demonstrate:

 

 

Any help in debugging is appreciated.

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

Link to comment
Share on other sites

I think you meant to do this:

http://codepen.io/anon/pen/bNzNVe?editors=101

 

Notice I'm not clearing the entire transform (just setting x and y to 0) and I'm calling update() on the Draggable since we're altering the values outside of it (we're basically telling it to re-calibrate itself and look at the current values, not trusting its own cached ones). Is that what you're looking for? 

  • Like 1
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.
×