使用 Css 更改颜色很容易。调用类并使用动画,
-webkit-animation属性。这两个属性调用了一种函数,你会以秒为单位传递时间(例如:animation: colorchange 50s;
-webkit-animation: colorchange 50s;
)。然后你改变函数内部的颜色,在我们的例子中它被称为“colorchange”。使用函数的方法是使用@keyframes colorchange
或@-webkit-keyframes colorchange
。很简单。另外要注意的是浏览器。对于像chrome safari这样的浏览器使用@-webkit -keyframes colorchange 并指定颜色。U 可以 c 魔术。一个明确的例子如下:
#Class .inner {
-moz-transition: height 0.2s ease-in-out, width 0.2s ease-in-out;
-webkit-transition: height 0.2s ease-in-out, width 0.2s ease-in-out;
-ms-transition: height 0.2s ease-in-out, width 0.2s ease-in-out;
transition: height 0.2s ease-in-out, width 0.2s ease-in-out;
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-flex-direction: column;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-moz-justify-content: center;
-webkit-justify-content: center;
-ms-justify-content: center;
justify-content: center;
-moz-align-items: center;
-webkit-align-items: center;
-ms-align-items: center;
align-items: center;
display: -ms-flexbox;
-ms-flex-align: center;
-ms-flex-pack: center;
background: #e74c3c; /*circle circle*/
border-radius: 100%;
width: 35em;
height: 35em;
padding: 4em;
text-align: center;
box-shadow: 0 0 0 1em #FFF;
cursor: default;
animation: **colorchange** **50s**;
-webkit-animation: **colorchange** **50s**;
}
@keyframes colorchange
{
0% {background: #e74c3c;}
15% {background: violet;}
30% {background:indigo;}
45% {background: blue;}
60% {background: green;}
75% {background: orange;}
90% {background: purple;}
100% {background: #e74c3c;}
}
@-webkit-keyframes colorchange /* Safari and Chrome - necessary duplicate */
{
0% {background: #e74c3c;}
15% {background: violet;}
30% {background:indigo;}
45% {background: blue;}
60% {background: green;}
75% {background: orange;}
90% {background: purple;}
100% {background: #e74c3c;}
}
希望它易于理解('-');