Yogesh Chauhan's Blog

How to add new elements with swing animation using JavaScript and CSS?

in CSS & JavaScript on February 14, 2021

In this post, I demonstrated how to create HTML elements using JavaScript. That’s what we are going to use to create elements.

We need to add texts inside the elements to make them visible. For that we can use innerHTML.

Let’s add HTML and CSS first.

I have opacity set 0 for p elements and opacity 1 for p elements with class .show.

I have added that variable i so that I can have a number to attach while creating the new p elements. For e.g. Item 3, Item 4, etc.

Let’s add create element functionality.

Now, to create swinging animation we need to add perspective to the parent div tag.

Just like this:

.div {
  perspective: 100px;

Also, we need to set transform property to -90deg for p tags and set it to none when the elements are shown using JavaScript. That will create a swing effect animation as soon as you add a new element.

Horizontal Swing animation

For Horizontal Swing animation, all we need to change is the transform property to rotateY(-90deg) from rotateX(-90deg).

Here is the live demo:

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
The Complete Basic Explanation of PHP SessionsPHPWhat’s new in Constructor in PHP 8?PHPHow to Clone Objects in PHP?MiscellaneousHow to Use SQL MAX() Function with Dates?SQL/MySQLHow to get front page or home page ID in WordPress?WordPressHow to Recognize an Array in JavaScript?JavaScriptHow to create a vertically rotating texts using CSS?CSSHow to Create a Copy of a Table in SQL and MySQL?SQL/MySQLThe substr() method in JavaScript and how it’s different from substring()JavaScriptHow to create a link tag button using CSS?CSSMIN, MAX, COUNT, AVG and SUM in SQLSQL/MySQLHow to read Standard Input in Swift?Swift