Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 equivalent to jQuery slideUp and slideDown?

My application is performing poorly with jQuery's slideDown and slideUp. I'm looking to use a CSS3 equivalent in browsers which support it.

Is it possible, using CSS3 transitions, to change an element from display: none; to display: block; while sliding the item down or up?

like image 911
Mike Avatar asked Feb 21 '11 23:02

Mike


People also ask

How do you toggle slideUp and slideDown in jQuery?

The slideToggle() method toggles between slideUp() and slideDown() for the selected elements. This method checks the selected elements for visibility. slideDown() is run if an element is hidden. slideUp() is run if an element is visible - This creates a toggle effect.

What is slideUp in jQuery?

The slideUp() is an inbuilt method in jQuery which is used to hide the selected elements. Syntax: $(selector). slideUp(speed); Parameter: It accepts an optional parameter “speed” which specifies the speed of the duration of the effect.

What is transition property in CSS?

The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Tip: A transition effect could typically occur when a user hover over an element.


1 Answers

You could do something like this:

#youritem .fade.in {     animation-name: fadeIn; }  #youritem .fade.out {     animation-name: fadeOut; }  @keyframes fadeIn {     0% {         opacity: 0;         transform: translateY(startYposition);     }      100% {         opacity: 1;         transform: translateY(endYposition);     } }  @keyframes fadeOut {     0% {         opacity: 1;         transform: translateY(startYposition);     }      100% {         opacity: 0;         transform: translateY(endYposition);     } } 

Example - Slide and Fade:

This slides and animates the opacity - not based on height of the container, but on the top/coordinate. View example

Example - Auto-height/No Javascript: Here is a live sample, not needing height - dealing with automatic height and no javascript.
View example

like image 134
TNC Avatar answered Sep 28 '22 04:09

TNC