简体   繁体   中英

GSAP and jQuery: play animation on the next page load

I have a simple animation I'd like to fire on a page after it has loaded.

I can fire the animation on window load using jQuery like so:

$(window).on('load', function(){
  myTimelineAnimation.play();
})

But this way only works when I manually refresh the page. I'd like it to fire every time when I go to the page via a link, or via the browser back button and on page refresh.

Is this possible?

Example timeline:

var myTimelineAnimation = new TimelineLite({paused:true});
    myTimelineAnimation
      .to(element, 0.5, {opacity: 1});

If the page is not ajax loaded, then just try

 $(document).ready(()=>{ // you code }) 

If it is, you need to handle the ajax loading event and trigger your event after the loading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM