Skip to content
Advertisement

How to replicate jquery animation sequence in vanilla js/css

As the title says, I would like to replicate the animation bellow. the jquery API https://api.jquery.com/toggle/ decibels this default behavior as so:

JavaScript

but I don’t understand how the transition works. I have tried changing the opacity, translating the element, ect, but obviously no luck. If it is impossible to do this in a simple way without jquery, an answer for the transition effect without the toggle function is also acceptable (but not hide() and show() as I have already tried those and couldn’t get it to work properly). And yes, I would prefer a swing transition if possible. any help is appreciated.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

I don´t know if I understood your question correctly but you want

JavaScript

in normal JS?

You have two options: set an data attribute to #elem or you check if #elem has the class .hide. But its easier to just add the css to the element

With data attribute:

JavaScript
JavaScript

Or with css:

JavaScript
JavaScript

If you still want the animation:

JavaScript
JavaScript
JavaScript

I hope I could help

Advertisement