Open In App

How to perform fadeOut() and slideUp() together in JavaScript ?

Given a document, The task is to perform the fadeOut() and slideUP() at the same time with the help of JavaScript. Here 2 approaches are discussed.

Approach 1:
First select the element. Use animate() method to perform the both operations, this method takes 4 arguments but in this case only 2 are used. First is the CSS that we want to animate and the second is speed. CSS is { height: 0, opacity: 0} and speed used is ‘slow’. Height property is used to perform the slideUp effect and opacity is used to perform the fadeOut effect.

Approach 2:
First select the element. Use animate() method to perform the both operations, this method takes 4 arguments but in this case only 2 are used. First is the CSS that we want to animate and the second is speed. CSS is { height: ‘toggle’, opacity: ‘toggle’} and speed used is ‘slow’. Height property is used to perform the slideUp effect and opacity is used to perform the fadeOut effect. This example can reverse the effect as well.


Article Tags :