YogeshChauhan.com
How to add new elements with swing animation using JavaScript and CSS?
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:

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress? Mar 3 substring() Method in JavaScript Mar 3 Window setInterval() Method in JavaScript Mar 2 How to zoom an element on hover using CSS? Mar 2 the box-sizing property in CSS

You might also like these

How to enable and disable button using JavaScript?JavaScriptHow to create a cross-browser smooth scrolling with jQuery?jQueryAngular 9 time clock update every minute, second, hourAngularWhat is the difference between Loosely Typed Language and Strongly Typed Language?MiscHTML Copyright SymbolHTMLDebugging in WordPress Part 2: WP_DEBUG_LOG and WP_DEBUG_DISPLAYWordPressCSS Overflow Property with ExamplesCSSHow to Validate User Name, Email Address and URL in PHP?PHPJavaScript Number MethodsJavaScriptThe SQL UNION OperatorSQL/MySQLGive buttons accessible namesUI/UXHow to check if a link has http or https in it in JavaScript?JavaScript