From our sponsor: Ready to show your plugin skills? Enter the Penpot Plugins Contest (Nov 15-Dec 15) to win cash prizes!
Today we’d like to explore a specific reveal effect with you. If you saw the Crossroads Slideshow a while back, you might have noticed the page transition when the content is shown after an image gets clicked. We call this type of transitions a “reveal” animation because some content is already there while an overlay element animates out, revealing what’s underneath.
To make such an effect is pretty straightforward: simply place an overlay with the same or different color of the page background and animate it out of the viewport; whatever is under it will show. But there are two challenges here: one is if you’d like the overlay itself to have some content which you want to conceal, i.e. which you want to get cut off while hiding it and not simply move along with the parent when animating it out. The other challenge is to add a rotation and guarantee that the overlay covers the whole screen so that no gaps are shown when you move it out. When combining these two effects, things get really interesting.
So let’s tackle these two challenges in this little tip today and show some of the many possibilities for how to use these techniques in a page design.
The demos are kindly sponsored by Northwestern: Earn your MS degree entirely online. If you would like to sponsor one of our demos, find out more here.
The reveal effect
The beauty of the reveal effect is that the technique is very simple, yet the result is so interesting: take any element that has its overflow set to “hidden” and animate it in some direction, while animating its child in the opposite direction. This creates a “cut off” look, the content appears to be steady in one place, as if we’re animating some kind of clipping mask. Yet we are only translating elements.
Under the hood, you can see what’s happening here:
We simply move a container up. Now, let’s keep the content in place by reversing that movement and translating it in the opposite direction:
One last step is to add overflow: hidden to the parent:
And that’s it! Now, if you want to spice things up a bit, you can add a different duration or easing to the reverse element or other animations to the inner elements.
Adding a rotation
The effect becomes a little bit more complicated when we want to add a rotation. When we rotate an element it will create gaps and not cover the background entirely anymore. So we need to make sure that it’s width and height is set in such a way that when rotated, there are no gaps.
Technically, we’re want the (minimum) bounding box of a rotated rectangle.
The following Stackoverflow thread gave us the right formula for our case: How to scale a rotated rectangle to always fit another rectangle
Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.
We only need to find the correct width and height, so the following bit is interesting to us:
“When you rotate an axis-aligned rectangle of width w and height h by an angle ɸ, the width and height of the rotated rectangle’s axis-aligned bounding box are:
W = w·|cos ɸ| + h·|sin ɸ|
H = w·|sin ɸ| + h·|cos ɸ|
(The notation |x| denotes an absolute value.)”
Additionally, we have to make sure that we keep the previous structure in place and that we show the content straight. So we need to rotate the content back. To ease our animation and not tinker with calculations we avoid moving the rotated content, but instead we’ll use the resized container for the motion.
In total we will use three containers to achieve all that:
<div class="content content--first"><!-- only rotated -->
<div class="content__move"><!-- resized and moved -->
<div class="content__reverse"><!-- reverse rotation -->
<!-- ... -->
</div>
</div>
</div>
If you look at the x-ray view of one of the demos, you can see the rotation and calculation of the new width and height:
Given this structure, there are really endless possibilities for rotated reveal and overlay animations.
Think of multiple overlays. Think of matching animations of the elements that are being revealed or the ones that get hidden.
There’s so much to explore!
Have a look at our little compilation, we hope you enjoy it!
Nice tutorial, thank you teacher 😀
Awesome, good read.
Very smooth and elegant as usual 🙂 Thanks!
This website is awesome 😀 You prove again and again how beautiful webdesign can be.
Nice and creative