I'm animating an element by unveiling it from the bottom of the page. The position of the child elements should not be affected by the size change of the unveiling animation.
That's what I'm looking for:

<div>
<h1>Hello stranger</h1>
</div>
Both elements are positioned absolute with top, right, bottom & left set to 0. The contents are revealed by lowering the top of the div from 100% to 0%. Have a Fiddle.
My goal is
- to keep the heading always at a fixed position (middle)
- hide the heading when it is not uncovered yet
But these are my problems (Fiddles included)
- When using
position:fixedfor theh1theoverflowbecomes always visible. - When using
position:absolutethe position isn'tfixedcorrectly. - When using
clip:rect(500px auto auto auto)I lose the ability to use%. And thus I can't determine the exact height of the viewport without using JavaScript.
What else can be done to archieve the described behavour without JS?
The solution is to move the
h1in the opposite direction to thedivanimation at the same time which gives the illusion that theh1has remained static. However theh1is actually also moving relative to thedivjust in the opposite direction.I've kept the same markup and also the
position: absolute; top: 0; right:0; left:0; bottom: 0;requirement you stated on both elements.http://jsfiddle.net/eLbcdc9c/6/
HTML
CSS
Apply the
hideclass to thediv(by clicking the toggle in the fiddle) and you should get the desired affect.Things that are important to note here is the use of 3dtransforms. These are much smoother than animating
topormarginsand takes advantage of using a devices GPU for Hardware acceleration to achieve this.3dtransforms are very well supported but you may need to apply the browser prefixes in some instances depending on the support you want to offer.