Animating non-animatable properties with CSS3 transitions

断了今生、忘了曾经 提交于 2019-12-01 07:38:40

visibility is an animatable property, see the spec.

Which means your .hidden class will work as you have described. Demo here: http://jsfiddle.net/ianlunn/xef3s/

Edit: the spec isn't perfectly clear:

visibility: if one of the values is ‘visible’, interpolated as a discrete step where values of the timing function between 0 and 1 map to ‘visible’ and other values of the timing function (which occur only at the start/end of the transition or as a result of ‘cubic-bezier()’ functions with Y values outside of [0, 1]) map to the closer endpoint; if neither value is ‘visible’ then not interpolable.

But this is what I believe it means:

visibility doesn't smoothly animate between a range of visible and hidden in the way that opacity animates between 1 - 0. It simply switches between visible and hidden at the start and end states of the transition.

Providing the transition is either going to or from visibility, then a transition will occur. If trying to transition between visibility: hidden and visibility: collapse for example, those values are "not interpolable" and the transition would not occur.

So in my example, opacity causes the element to fade out and then at the end of the transition, visibility snaps to hidden.

As a good alternative to display/visibility toggle, opacity:0 with pointer-events:none could be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!