Jump to content
GreenSock

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

Tween SVG <img> color

Recommended Posts

I have seen that pretty much all of the SVG animations involve embedding the XML directly into the page and using GSAP to manipulate the various properties and attributes. I am looking to see if it is possible to animate SVG by simply embedding it in an <img> tag. Here is a simple example I am looking to do to tween the SVG color on rollover but it doesn't seem to be taking it. These SVG elements are going to be implemented through a CMS so I was thinking that including them with an <img> tag would make much sense...but I wanted to see if there might be any limitations with this type of implementation.

 

See the Pen 68edca4dc80abf6b495c16f7acb00997 by bdang (@bdang) on CodePen

Link to comment
Share on other sites

Adding your SVG via <img> element will prevent manipulation with JavaScript. You can get some control of it with CSS, but it has to be part of the SVG code. External stylesheets won't work on the nested elements.

 

You'll have the most control and options by putting the code inline. That being said, we have had some discussions about injecting the code. Here are a couple threads that may be of interest to you.

 

Happy tweening.

:)

 

  • Like 5
Link to comment
Share on other sites

This is what I thought.  Thanks for the confirmation PointC...it's much appreciated.

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