请检查演示:https://jsfiddle.net/6rtnL7a7/css3是否可以根据宽度改变颜色?
.line{
height:2px;
width: 200px;
background:red;
cursor: pointer;
position:relative;
&:hover:after {
content: '';
display:block;
position: absolute;
top:0;
left:0;
width: 0px;
height:2px;
background:blue;
animation-duration: 1s;
animation-name: example;
animation-fill-mode: forwards;
}
&:after {
content: '';
display:block;
position: absolute;
top:0;
left:0;
width: 0px;
height:2px;
background:blue;
animation-duration: 1s;
animation-name: back;
animation-fill-mode: forwards;
}
}
@keyframes example {
from {
width: 0;
}
to {
width: 100%;
}
}
@keyframes back {
from {
width: 200px;
}
to {
width: 0;
}
}
很抱歉的混乱。
动画工作正常,但如果线变为这样 https://jsfiddle.net/916er24k/宽度方法的箭头将无法工作作为animiation宽度从0到200的宽度开始,是有另一种方式呢?
颜色从0%变为100%?
你的意思是把红色的酒吧变成蓝色吗? –
您可以使用背景(单色渐变),背景重复和背景大小或位置。你能否澄清这个问题。你的演示似乎工作。 –
这可能会使用渐变并限制动画中的“步骤”。 –