Jump to content
GreenSock

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

Starting TweenMax from an onClick event instead of 'autoplay'

Go to solution Solved by Diaco,

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

Greetings!

I have my first TweenMax doing everything i need, (including interaction with externals controls/buttons) but I'm drawing a blank as how to prevent it from 'autoplay'

 

 

My relevant 1liner:

var tl =  TweenMax.to(point, currentSpeed, {css: { left: "95%"}, repeat:repeat, yoyo:true, repeatDelay:0, ease:Linear.easeNone});

... so for example my 'pause' button works fine:

$('#pause').click( function(){tl.pause();});

... how do I make it start only when I press my $('#start') button? 

I figure I missed something simple, hence my apologies and thanks in advance.

 

Link to comment
Share on other sites

  • Solution

Hi tomekpilot  :)

 

You need to add paused:true in your Tween Vars , pls try this :

var Anim = TweenMax.to( "#foo" , 1  ,{ ....... , paused:true }) ;

$('#play').click( function(){  Anim.play()  }) ;

pls check this out , same method with Timeline :

 

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

  • Like 5
Link to comment
Share on other sites

... ahhhh, that's what what I meant by 'something simple'.Thanks! works like magic now.

Link to comment
Share on other sites

To add to Diaco.AW's great advice.. here is how to start with timeline paused using TimelineMax / TimelineLite:

var Anim = new TimelineMax({paused:true});

Anim.to("#foo", 1, {left: "95%"});

$("#play").click(function(){ Anim.play() }) ;

:

Hope this helps! :)

  • Like 4
Link to comment
Share on other sites

  • 4 months later...

Same thing. You just need to type a few extra characters

var Anim = new TimelineMax({paused:true});

Anim.to("#foo", 1, {left: "95%"});

document.querySelector("#play").addEventListener("click", function(){ Anim.play(); });
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

Does anyone know how to change this from targeting...

 

#foo

 

to targeting...

 

$(this).closest('.foo')

 

so that I'm animating the nearest .foo ancestor of the clicked element?

 

Thanks!

Link to comment
Share on other sites

Just add an animation to your click function. Here's an example with a bunch of nested foo classes. It doesn't use jQuery, but it's the same concept.

 

See the Pen MwRgrw by osublake (@osublake) on CodePen

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