我看到CSS3的標籤,所以這裏是一個純粹的CSS3例如:
.block {
transition: opacity 0.5s linear, transform 0.5s linear;
opacity: 1;
}
.block.hidden {
opacity: 0;
transform: scaleY(0);
}
這裏的小提琴:http://jsfiddle.net/andunai/1e21endf/
然而,在這種情況下,元素將僅僅消失在視覺上,並且不會釋放它所需的位置,因此您必須最終使該元素具有position: absolute
或animage padding
,margin
和max-height
- 注意的height
過渡仍然存在問題:How can I transition height: 0; to height: auto; using CSS?
.block {
transition: opacity 0.5s linear, transform 0.5s linear, max-height 0.5s linear, padding 0.5s linear;
opacity: 1;
max-height: 30px; /* This one must be approximately of the
height of element, not less */
}
.block.hidden {
opacity: 0;
max-height: 0;
padding: 0;
transform: scaleY(0);
}
這裏的加入幾乎真實的縮放的例子:http://jsfiddle.net/andunai/1e21endf/1/
隱藏和顯示不會給一個效果嘗試jQuery的淡入,淡出 – 2014-12-04 12:43:48
你應該'jQuery'庫,也就是提供了許多這種類型的功能 – Girish 2014-12-04 12:45:27