Jump to content
Search Community

Newbie - fromTo using css

Guest struthyBhoy
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

Guest struthyBhoy

Hi,
 
I am a newbie here, so I hope i am not annoying anyone to much with this question.
 
I want to animate some css selectors. I am using TweenMax.
 
This is the code I have - I would also like to tween the opacity from 0 to 1 and add a ease:Bounce.easeOut. 

 

Any help appreciated. 

var head = $(".banner-home-text h1"),
var tl = new TimelineLite();
tl.fromTo(head, 0.5, css:{marginTop:400}, css:{marginTop:0});
Link to comment
Share on other sites

Guest join_shailesh

tl.fromTo(head, 0.5,{ css:{marginTop:400}, opacity:0, ease:Bounce.easeOut}, { css:{marginTop:0}, opacity:0,ease:Bounce.easeOut});
 
Try this-----------

Link to comment
Share on other sites

Guest struthyBhoy

That didn't work, thanks though. I got it kind of working with this, but I cant seem to get other elements in the timeline with this.


 var h1 = new TimelineLite()

 h1.from('.banner-home-text h1', 2, {
 	css:{marginTop:400, opacity: 0},
 	ease:Bounce.easeOut,
 	// /delay: 6
  });

Link to comment
Share on other sites

Guest struthyBhoy

I have got what I want, I think I can work from this code. Thanks for the help

	var h = $("h1"),
 	  para = $("p");

	var t1 = new TimelineLite()


	 t1.from(h, 2, {
	 	css:{marginTop:400, opacity: 0},
	 	ease:Bounce.easeOut,
	 	// /delay: 6
	  });

	  t1.from(para, 2, {
	 	css:{marginTop:400, opacity: 0},
	 	ease:Bounce.easeOut,
	  }, "-=1.3"
	);

Link to comment
Share on other sites

 

I have got what I want, I think I can work from this code. Thanks for the help

	var h = $("h1"),
 	  para = $("p");

	var t1 = new TimelineLite()


	 t1.from(h, 2, {
	 	css:{marginTop:400, opacity: 0},
	 	ease:Bounce.easeOut,
	 	// /delay: 6
	  });

	  t1.from(para, 2, {
	 	css:{marginTop:400, opacity: 0},
	 	ease:Bounce.easeOut,
	  }, "-=1.3"
	);

 

Glad you got it working! FYI, it also works without the css:{...} declaration, in most cases. 

Link to comment
Share on other sites

be careful with those trailing commas. When I work in "use strict" mode the commas would error out.

Also, like flysi300 said you don't need to wrap the CSS anymore.

t1.from(h, 2, {
 marginTop: 400,
 opacity: 0,
 ease: Bounce.easeOut
});
t1.from(para, 2, {
 marginTop: 400,
 opacity: 0,
 ease: Bounce.easeOut
}, "-=1.3");
Link to comment
Share on other sites

Hello struthyBhoy, and Welcome to the GreenSock Forum!

 

Instead of tweening opacity you can tween autoAlpha, which will also give you better performance.

 

See the CSSPlugin Docs:

  • autoAlpha
    Identical to opacity except that when the value hits 0 the visibility property will be set to "hidden" in order to improve browser rendering performance and prevent clicks/interactivity on the target. When the value is anything other than 0, visibility will be set to "inherit". It is not set to "visible" in order to honor inheritance (imagine the parent element is hidden - setting the child to visible explicitly would cause it to appear when that's probably not what was intended). And for convenience, if the element's visibility is initially set to "hidden" and opacity is 1, it will assume opacity should also start at 0. This makes it simple to start things out on your page as invisible (set your css visibility:hidden) and then fade them in whenever you want.
Example of usage:
//fade out and set visibility:hidden
TweenLite.to(element, 2, {autoAlpha:0});

//in 2 seconds, fade back in with visibility:visible
TweenLite.to(element, 2, {autoAlpha:1, delay:2});

Hope this helps!

 

:)

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