Jump to content
Search Community

Applying perspective transforms to SVG

bromel 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

Hi all,

I am just experimenting with 3d transforms on SVG elements, i have done a simple pen and been looking into Intro to CSS 3D for some ideas on how to implement. I have done a simple pen and tried to implement it without success. I have seen many examples with html and css and was wondering if the principle is the same in implementing to work. Any help/resources/examples would be greatly appreciated.

 

many thanks

 

bromel

See the Pen LYYYLRG?editors=1010 by w9914420 (@w9914420) on CodePen

Link to comment
Share on other sites

2 minutes ago, bromel said:

I am just experimenting with 3d transforms on SVG elements

 

Sorry, 3d transforms on SVG elements isn't supported. I think the only browser that can correctly do 3d transforms is Firefox. If you want to do 3d stuff, you'll need to wrap your SVG in a div, and do it the CSS way.

  • Like 5
Link to comment
Share on other sites

  • 1 year later...

Just wanted to share that if you want to animate e.g. an image or any other SVG element that can be reproduced with HTML & CSS, you can use SVG's <foreignObject> and animate it with GSAP then. E.g.:

 

<svg>

    <foreignObject x={0} y={0} width={1920} height={1080}>

        <div xmlns="http://www.w3.org/1999/xhtml">

            <img id="img" width={1920} height={1080} src="/foo.png" />

        </div>

    </foreignObject>

</svg>

Link to comment
Share on other sites

  • 2 years later...

After finding this post and discovering that perspective effects don't work inside inline SVG files, as well as the "rotationY" tweens with GSAP, I made it using CSS variables and setting an upscale in relation to the angle using some utilities (+ a small shadow effect).

Not the perfect result, but much better than nothing and my client was happy with the final result.

I hope this helps in this case too, maybe some improvement ideas will come...

See the Pen XWGxRMm by jester6 (@jester6) on CodePen

  • 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.
×
×
  • Create New...