Skip to content
Advertisement

Css transition absolute to fixed

I have a child inside a parent and I would like to animate child from its start position to page bottom into fixed position. Obviously animation is not “full” because position changes from absolute to fixed when animation starts, which I understand breaks the animation. Would this be possible to achive somehow ? I dont mind some more html if necessary.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

An approach I’ve used is animating the element while it still has absolute positioning, then right after it’s done animating, add a fixed position value to it.

And to achieve this, the element is first appended to the body, so it can move within the bounds of the document, which is basically the entire screen. And in case the element is to be returned back to it’s original position, the takeMeBack() function does the whole job, which in this case every successive click either does the animation or undoes it.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement