简体   繁体   English

显示属性上的CSS过渡不起作用

[英]CSS transition on display property doesn't work

I've set up a function: 我已经设置了一个功能:

function removeDiv(el){
    var elem = document.getElementById(el);
    elem.style.transition = "display 2.5s linear 0s";
    elem.style.display = "none";    
}

and created a div which has the function called onclick. 并创建了一个具有onclick功能的div。 However when I click on the div it disappears immediately without transitioning. 但是,当我单击div时,它会立即消失而不会过渡。 Are display transitions not supported - can it be either one state like 'block' or another? 是否不支持显示转换-它可以是一种状态,例如“阻止”还是另一种状态? Thanks for looking! 感谢您的光临!

display is not a property that can be animated. display不是可以动画的属性。 Try opacity instead. 尝试opacity

For future reference, here is the official specification of all properties that can be animated: http://www.w3.org/TR/css3-transitions/#animatable-css 为了将来参考,以下是可以动画化的所有属性的官方规范: http : //www.w3.org/TR/css3-transitions/#animatable-css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM