Yogesh Chauhan's Blog

Create a menu with a curtain falling animation using CSS and JavaScript

in CSS & JavaScript on May 30, 2021

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.

Give the gift of Audible

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:

How to create a flip effect with CSS?


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
What’s the difference between variables in CSS and SCSS (Sass)?CSSHow to set the permissions on all files and folders in Mac?MiscellaneousWhat are keys in React?ReactIntroduction to components and templates Part 1: Component MetadataAngularWhat is iFrame in HTML? Why do we need it?HTMLHow to get user’s Browser and Operating Systems information using PHP?PHP