EddieGreen
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
Downloads
Posts posted by EddieGreen
-
-
Super stuff and thanks for the response. Let's get to it...
On 2/1/2023 at 3:27 PM, Rodrigo said:based on the error you're getting, you are creating a circular reference which means that you are trying to Stringify an object that has a reference to itself inside:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
Yah well I figured that out real quick and got the solution too..
Before I got into fixing recursive references, I reached out to ask the fundamental questions
Question 1: Is it possible to save animation state between page loads?
Question 2: If it is possible, how would you implement this?
I realise now that I made a mistake in offering any code. Forget my code. How would you achieve the result?
-
I'm using GSAP to manipulate an SVG map. See pen, based on @OSUblakes fine work with
See the Pen oGoyYb by osublake (@osublake) on CodePen
I'd like to be able to maintain the map's position following a page refresh or ajax call for updated content. The whole SVG content will change although the bounds will not - the change would be in the icons.
I've already attempted to save what I think might be useful in
but get errors storing the object data. It doesn't help that I'm not a JavaScript man, as might be obvious with the following code that spits out it's dummy at the point of storing object withsessionStorage
TypeError: cyclic object value
Is what I'm trying to do possible, and if so, how?See the Pen dyjLbPm by EddieGreen (@EddieGreen) on CodePen
Saving animation state between page loads
in GSAP
Posted
To answer my own question...
The position, scale and orientation is modified on the SVG object - this is where to look to save and restore the state of the SVG.
The scale and position are in the
viewBox
attribute, orientation indata-svg-origin
andtransform
, for example in the demo shown:Add a function to store these values in session, or elsewhere, for example:
Call this function whenever the map changes - for example at the end of the drag:
At page initialisation, read these values and modify the SVG attributes with saved values if any:
Finally, remove the stored session when required, fore example when the SVG is set to original size etc:
A working demo and the code referred to is here