Jump to content
Search Community

animating a div <img> vs background-image

keldon 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

I am just getting started with GSAP for JS and I am wondering which is more cross-browser friendly and/or performant :

  1. a DIV element containing an IMG element
  2. a DIV with it's style object's background-image set (via CSS or JS)

I am going to be scaling and rotating and it needs to work in the oldest IE that GSAP supports.  (as well as all the current and better browsers)

 

Thanks for pointing me in the right direction,

Keldon

Link to comment
Share on other sites

Hello keldon, and Welcome to the GreenSock Forum!

 

Best thing to is try both and see what is best for your situation and project.

 

Here is a codepen example of animating both an image tag and a div tag with a background-image:

 

My example:

See the Pen ykJnb by jonathan (@jonathan) on CodePen

 

If you look at the Tweens you will see that i am using the special property called force3D:true to tell the browser to use Hardware Acceleration for smoother animation. Try testing it in different browsers to see how it behaves in multiple browsers. But GSAP is very performance driven.

 

Also some nice reading to learn more about 3D transforms:

Best thing to do is test, test, test, to see what works best for your code.

 

I hope this info helps! :)

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