Jump to content
GreenSock

mhd_arif

centering svg object with gsap

Recommended Posts

hello everyone, i'm wondering how can i centering my svg object exactly in the center of the screen.

I give a style for my svg like position: absolute, top:0,left:50%, transform: translate(0,-50%). how can i move it to the center of the screen with gsap?

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

 

I think its best to just let GSAP handle the translation and positioning like so

TweenMax.to("svg", 1, {left:"50%", top:"50%", yPercent:-50, xPercent:-50});

http://codepen.io/GreenSock/pen/LNEjrG

 

Read more about xPercent and yPercent: http://greensock.com/gsap-1-13-1

 

In the future please consider providing a CodePen demo as it helps us better understand the issue. 

 

Thanks

Link to comment
Share on other sites

many thanks for the answer carl. sure, i will provide a codepen demo for the next question.

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

 

I think its best to just let GSAP handle the translation and positioning like so

TweenMax.to("svg", 1, {left:"50%", top:"50%", yPercent:-50, xPercent:-50});

See the Pen LNEjrG by GreenSock (@GreenSock) on CodePen

 

Read more about xPercent and yPercent: http://greensock.com/gsap-1-13-1

 

In the future please consider providing a CodePen demo as it helps us better understand the issue. 

 

Thanks

 

I was having issues with the arcs going off the page when rotating. I finally just changed the viewBox in the SVG. So would it be better to let GSAP do this? Also for scaling?

 

See the Pen eZmzKM?editors=1100 by RhinoRudi (@RhinoRudi) on CodePen

 

Thanks

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