Jump to content
Search Community

SVG shapes positioning with <USE> tag

yesworld test
Moderator Tag

Recommended Posts

Hi everyone!

 

Sorry, if the answer is already there, but I couldn't find it.

 

I have 2 SVG tags.
1) Source SVG sprite with 2 <rect> shapes.
2) And the second SVG is pulling elements from the first SVG with <use> tag.

 

The task is to move both shapes from the source SVG to the same point (x, y) using your library. Now they are moving together and to different points. 

Thanks for your attention, and any help would be greatly appreciated. 

 

Thank you! 

See the Pen LYNEZBE by yesworld (@yesworld) on CodePen

Link to comment
Share on other sites

Hey yesworld and welcome to the GreenSock forums.

 

Do you really need to use <use> elements? They're not performant and it's substantially easier to do what you're trying to do using regular SVG elements instead. If you need to duplicate things then I recommend just duplicating the SVG itself. If things need to be dynamic you can clone it via JS.

 

Let me know.

  • Like 1
Link to comment
Share on other sites

I need to dynamically include svg files. From there I will extract the sprites. Which will then be used for drag and drop plugins.

 

But, If I use svg copies, then when hovering over the shapes, the interaction area will be the square of the svg element, and not the silhouette of the shape.

Link to comment
Share on other sites

34 minutes ago, yesworld said:

If I use svg copies, then when hovering over the shapes, the interaction area will be the square of the svg element, and not the silhouette of the shape.

No, I think you're mistaken there. If you copy an inline SVG you can still refer to the inner parts of the clone. That sounds like the way to go here (if you can't just use the original inline SVG).

Link to comment
Share on other sites

10 hours ago, ZachSaucier said:

No, I think you're mistaken there. If you copy an inline SVG you can still refer to the inner parts of the clone. That sounds like the way to go here (if you can't just use the original inline SVG).

Yes, you are right. BUT, I'm dynamically include the SVG file with sprite (example #sprite-draggable) that need to be draggable.

And I have to drop this sprite into another SVG (#workspace) tag. The dropzone will not work on the second SVG tag.

 

See the Pen gOrbGyO?editors=1010 by yesworld (@yesworld) on CodePen

Link to comment
Share on other sites

11 hours ago, ZachSaucier said:

No, I think you're mistaken there. If you copy an inline SVG you can still refer to the inner parts of the clone. That sounds like the way to go here (if you can't just use the original inline SVG).

Sorry, right now I just realized what you exactly meant, I'll try to do so. Thank!

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