Jump to content
Search Community

Dragging masked SVG path

Pola86 test
Moderator Tag

Go to solution Solved by OSUblake,

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

Hello everyone,

 

I'm looking for a hint, as you can see in the Codepen attached I managed to drag a masked SVG circle around the container, problem is when I want to use a path as a mask I don't know how to get the coordinates (for path there's no "cx" and "cy").

Any suggestions on how I could accomplish this?

This is the function that does the trick with a circle

//move the mask with the drag
function onThrowUpdate() {

  var posX = parseInt(rocketHole.getAttribute('cx')) + this.target._gsTransform.x;
  var posY = parseInt(rocketHole.getAttribute('cy')) + this.target._gsTransform.y;

  TweenMax.set(rocketMask, {
    attr: {

      cx: posX,
      cy: posY

    }

  })

See the Pen KNeZOE by Polenji86 (@Polenji86) on CodePen

Link to comment
Share on other sites

  • Solution

There are coordinates on a path, but you gotta do some work. I think the easiest solution might be to convert the path data to relative coordinates. That will let you modify the first Move command without affecting the rest of the path. There's a bunch of tools out there to convert it to a relative path. I just used Snap.

See the Pen 4216a3f62dc149b7fce3b2d3868629d5?editors=0010 by osublake (@osublake) on CodePen

 

I think there might be a way to get an SVGPoint from the path and animate it like I do in this post. Notice how I don't have to do any updates. Animating the point directly eliminates the need for any manual updates. I'll have to look into that.

http://greensock.com/forums/topic/15270-animating-waves-with-gsap/?p=66401

  • Like 4
Link to comment
Share on other sites

:lol:  :lol:  :lol:

 

Love it!!!

 

A poster of this should be included with the Club GreenSock membership.

 

The only thing I don't like about it is my character. Everybody else is doing something cool, like levitating or holding a weapon. I'm stealing fish??? If you're going to associate fish with me, at least give me some explosives.

  • Like 6
Link to comment
Share on other sites

:lol:  :lol:  :lol:

 

Love it!!!

 

A poster of this should be included with the Club GreenSock membership.

 

The only thing I don't like about it is my character. Everybody else is doing something cool, like levitating or holding a weapon. I'm stealing fish??? If you're going to associate fish with me, at least give me some explosives.

 

If someone could track down Jonathan in the real world and snap a picture of him, I would order a printed poster myself.

 

As for you and your fish, Blake, I think it is a fitting match. Must say that I did not think you were stealing the fish, more like you were the lord of them fishes... Diaco hasn't complained about having a lamb. 

  • Like 5
Link to comment
Share on other sites

Hello Pola86

 

That has to do with the way the SVG spec is. So any element with display none will be removed from the render tree.

 

You can find more about that here:

 

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/display

 

When applied to a container element, setting display to none causes the container and all of its children to be invisible; thus, it acts on groups of elements as a group. This means that any child of an element with display="none" will never be rendered even if the child has a value for display other than none.

  • When the display attribute is set to none, then the given element does not become part of the rendering tree.

So you either have to use the visibility attribute on your SVG element or use visibility:hidden in your css

 

Resources:

SVG visibility attribute: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/visibility

CSS visibility property: https://developer.mozilla.org/en-US/docs/Web/CSS/visibility

 

:)

  • Like 4
Link to comment
Share on other sites

Hello Pola86

 

That has to do with the way the SVG spec is. So any element with display none will be removed from the render tree.

 

You can find more about that here:

 

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/display

 

When applied to a container element, setting display to none causes the container and all of its children to be invisible; thus, it acts on groups of elements as a group. This means that any child of an element with display="none" will never be rendered even if the child has a value for display other than none.

  • When the display attribute is set to none, then the given element does not become part of the rendering tree.

So you either have to use the visibility attribute on your SVG element or use visibility:hidden in your css

 

Resources:

SVG visibility attribute: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/visibility

CSS visibility property: https://developer.mozilla.org/en-US/docs/Web/CSS/visibility

 

:)

Thanks Jonathan, very helpful, now it's working like a charme, thanks everybody

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