The basic concept of making the curtain falling effect lies in the CSS perspective property.
Using this perspective property, we can add some perspective to an element that are positioned in 3D. It determines the distance between the z=0 plane and the user or in other words, it determines how far the object is away from the user. So, a lower value will result in a more intensive 3D effect than a higher value.
Let’s go through the step by step process of creating it.
Step 1: HTML
Let’s create a menu button and menu section first.
Step 2: CSS
Let’s add some basic CSS to organize the menu and buttons. The same concept of adding menu absolutely positioned and organizing elements using flex.
I am using SCSS but you can always convert it to a CSS using any online or offline convertors.
Step 3: JavaScript
Just some basic JavaScript code, getting the elements using getElementById method and changing the display property of the menu container.
Now, you can click on the button and toggle the menu visibility.
const menu = document.getElementById("menu");
document.getElementById("menu-button-open").addEventListener("click", function() {
menu.style.display = "block";
});
document.getElementById("menu-button-close").addEventListener("click", function() {
menu.style.display = "none";
});
Step 4: Animation
As I’ve mentioned earlier, we’re going to use CSS perspective property with transform-origin property to create the animation using @keyframes.
Similar animation post:
animation examples menu onclick perspective property transform transform-origin