Jump to content
Search Community

Trigger GSAP from HTML file

bakisb test
Moderator Tag

Recommended Posts

Hey There!

I am very new on GSAP. ( and also on codes )

I prepare a simple timeline, and I want to make timeline started, when it is triggered from html side.

 

Because, I want to put those pages in a playout system. That is loading pages way before they are going to be at stage, when all the animations already played...

But there is a code to communicate to the system, saying, ok its your turn to the page... 

Which I want to add a trigger code, to start my anims on js file...

 

I tried to find some but there are nothing but the scroll trigger :)

 

Would anyone helps please...

 

Regards.

Bakis

 

Link to comment
Share on other sites

I'm not sure I understand your question and you didn't provide a minimal demo so it's difficult to know the context, but it sounds like you need to just wrap your animations in a function, and then only call that function when that page is displayed. This isn't really a GSAP-related question - it's an application engineering one. We really try to keep these forums focused on GSAP-specific questions if possible.

 

Happy tweening!

Link to comment
Share on other sites

well, thank you for quick response :)

this is my js file code;

 

var gstl = new gsap.timeline({ defaults: {duration: .5}})
 
gstl    
    .fromTo('.bg2', {x: '-100vw'},{x: '0vw'})
    .fromTo('.habergorsel', {x: '-100vw'},{x: '0vw'ease: 'back'})
    .fromTo('.haberbaslik',{scale:'0'},{scale: '1'ease: 'back'},'<')
    .fromTo('.haberspot',{y: '100vw'}, {y:'-14.1vw'ease: 'power3'},'<')
    .fromTo('.timefg', {scaleX: '0'},{scaleX: '1'ease:'none'duration: '10'},'<')
    .fromTo('.bg2', {opacity: '1'}, {opacity: '0'})    

 

and this is the code that I want to trigger the one above, from html file;

 

function BroadSignPlay(){ //set up
  gsap.timeline.pause()
}

 

and it is not working :(

 

thank you.

 

 

Link to comment
Share on other sites

A couple of issues:

  1. You don't need the new keyword when creating timelines.
  2. When trying to use a control method (like .pause()) on a tween or timeline, you need to use a variable of that tween or timeline. For you that'd be:
    gstl.pause()

     

Side notes:

  • 0.5 is the default duration in GSAP so you could probably leave that out.
  • It's best to use relative tweens (.to() and .from()) instead of .fromTo()s whenever you can.

I think you'd learn from my article about animating efficiently.

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