In a function e.g. "trackAnimationTime" - going from the horizontal to vertical layout.
"On Layout Unload" handler ("Horizontal" layout)
Get the current time of the animation timeline You are running: "Main Timeline" in this case and using a global variable named currentTimeMain...
window.currentTimeMain = hypeDocument.currentTimeInTimelineNamed('Main Timeline');
"On Layout Load" handler ("Vertical" layout):
hypeDocument.goToTimeInTimelineNamed(currentTimeMain, 'Main Timeline');
Note: I've shown this going from just one layout to another. You will need to adapt a more robust script so You can swap any needed layouts, such as going back to the horizontal from the vertical, the opposite of what we've just done.