我看到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