Jump to content
GreenSock

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

reset all animations when returned to page

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

I've set up a bunch of animations to play before I redirect the user to another url. When the user uses the back button to return to the animated page I need the animations to reset to their starting positions. Instead the animations remain in their completed states. How do I achieve this?

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

I've never heard of this behavior where an animation or any other dynamic layout change is preserved after visiting another page and then returning.

 

For instance you can click the JavaScript (JS) link at the top of the left navbar on this page and go back and forth as much as you want and the animation always starts fresh. 

 

If possible please post a link to a very simple example and let us know what browser you are seeing this in.

Link to comment
Share on other sites

Hi,

 

Yep Carl it has happened before I remembered a thread regarding the scrollTo plugin:

 

 

Jamie pointed to some browser issues in this post:

 

 

The main trouble makers are opera and safari 5, there's no safari 6 for windows yet so I can't say how it behaves.

 

Using  the following code works:

var	tl = new TimelineMax({paused:true, onComplete:tlComplete});

function tlComplete()
{
	//Redirect to new location
}

$(window).on('unload', function(){tl.seek(0);});

I've created a simple sample to check:

 

 

Hope this helps,

Cheers,

Rodrigo.

  • Like 2
Link to comment
Share on other sites

Good job, Rodrigo. Very helpful

Link to comment
Share on other sites

I don't have either browser. This is a problem that can affect any page with animations running, with those specific browsers? Depending on your type of website, it may take years to realize you suffer this problem if nobody bothers to tell you...

Link to comment
Share on other sites

Hi Gabriel,

 

Well is a little ominous to think that it may take years to realize the problem. The fact is that different browsers work in different ways, even with chrome and safari being webkit based they respond in different ways to particular scenarios.

 

As far as having the browsers installed, I'll encourage you to do so, even with opera being the long forgotten one there's still a small chance that someone using opera might land on your site, therefore is a very healthy practice to test as much as you can.

 

In the matter of this affecting any page, well as Carl pointed out this are the only two cases mentioned in the forums since the engine was released for JS and they depend, I believe, in browser cache and the circumstances are very different. While Brigitte's case involved page refresh, this one has to do with the user clicking the browser's back button. My advice would be to just keep your eyes open and remember this two issues, as you can see is not a hard thing to detect and neither hard to solve.

 

Cheers,

Rodrigo.

Link to comment
Share on other sites

  • 7 years later...

hi rodrigo,

 

the "unload"-snippet works fine on modern browsers (ff 77) but doesn't work on Safari 11.1.2.

maybe it's the same with flash, back in the days, where the browser back button wouldn't work for several years until the deeplink feature (js) came around.

i'm wondering why gsap 3.0 didn't provide a good fix for this... 

 

any chance you have an another solution?

 

thanks!

Link to comment
Share on other sites

1 hour ago, eezz said:

the "unload"-snippet works fine on modern browsers (ff 77) but doesn't work on Safari 11.1.2.

Are you saying that Safari 11 doesn't fire that event? 

 

1 hour ago, eezz said:

i'm wondering why gsap 3.0 didn't provide a good fix for this...

As Rodrigo shows, GSAP allows you to reset animations incredibly easily. Whether or not an event fires in a particular browser like unload is unrelated to GSAP's functionality.

Link to comment
Share on other sites

I have no idea why you would even need to use unload for an animation as it won't wait for it to finish without some hacks.

  • Like 1
Link to comment
Share on other sites

hello zach,

 

yes, Safari doesn't fire the event, Firefox does it and the intro animation works like it should be.

 

@OSUblake the problem is situated as follows. i have a homepage with a stagger-animation of 3 sections, if you click one section i redirect to another page, until here everything is fine, but when you hit the browser back button Safari gives me an empty page since the animations where triggered and maybe cached or something, the same goes for FF. if i code the unload-snippet into it it goes well for FF but not for Safari. 

 

if you have a better solutions, please share :) thx

Link to comment
Share on other sites

Do you have a demo of that? I've never seen anything like that happen before.

 

 

  • Like 1
Link to comment
Share on other sites

Probably has to do with you dynamically changing the location. You might need to use cache busting url.

https://stackoverflow.com/a/14197329/2760155

 

Or force it to reload.

https://stackoverflow.com/a/14197317/2760155

 

But I would probably start with calling the animation on load, or maybe using barba to do the route changes.

https://barba.js.org/

 

  • Like 3
Link to comment
Share on other sites

thanks, i'm gonna check those links and see where it brings me :)

 

Link to comment
Share on other sites

@OSUblake & @ZachSaucier

 

everything works fine on both browsers. 2 different timelines, a setTimeout() with a function including the linked page and a seek(0) for one of the timelines did the job.

 

cheers!

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