CSS动画自定义属性/变量 [英] CSS animate custom properties/variables
问题描述
我一直在努力使它工作一段时间.
I have been trying to get this to work for a while.
重点是内部div将具有某种形状,并且可能会有多个形状(这就是我使用nth-child
选择器的原因).
应该显示此内部div,然后将其再次隐藏一段时间.
问题是,我想在一个动画中为所有(后来的)多个内部div设置动画.为此,我认为我可以使用CSS变量,但这似乎不起作用.
The point is that the inner div will have some shape and there will probably more than one (That's why I used the nth-child
selector).
This inner div is supposed to be shown and then be hidden again both for some set amount of time.
the problem is, that I would like to animate all the (later) multiple inner divs in one animation. For this I thought I could use CSS variables, but this does not seem to work.
在这个示例中,我试图归档的是内部div基本上只是通过使用变量来闪烁.但是我在Firefox中的结果只是一个黑匣子.
What I am trying to archieve in this example is the inner div basically just blinking by using the variable. But my result in Firefox is just a black box.
我错过了什么吗?我已经检查了是否甚至可以在@keyframes
中使用CSS变量,并且可以肯定.
动画中它们的唯一问题似乎是它们之间没有插值,但是它们突然切换了,在这种情况下这不是问题.
Am I missing anything? I already looked up if one could even use CSS variables in @keyframes
and sure enough you can.
The only problem with them in animations seems to be that they are not interpolated in between but that they suddenly switch which is not a problem in this case.
@keyframes test{
from{
--one: 0;
}
to{
--one: 1;
}
}
#test{
width: 100px;
height: 200px;
background-color: black;
animation: test 1s infinite;
}
#test :nth-child(1){
width: 20px;
height: 20px;
margin: auto;
background-color: white;
opacity: var(--one,0);
}
<div id="test">
<div></div>
</div>