.logofont{ text-align: center;
background-image: -webkit-linear-gradient(left, #00C80D, #960CFF 25%, #DC2626 50%, #E6D205 75%, #147B96);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: masked-animation 4s infinite linear;}
@-webkit-keyframes masked-animation {
0%{ background-position: 0 0;}
100% { background-position: -100% 0;}
}
下面是网上找来的:
<style>
.masked{
text-align: center;
background-image: -webkit-linear-gradient(left, #147B96, #E6D205 25%, #147B96 50%, #E6D205 75%, #147B96);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-background-size: 200% 100%;
-webkit-animation: masked-animation 4s infinite linear;
}
@-webkit-keyframes masked-animation {
0%{ background-position: 0 0;}
100% { background-position: -100% 0;}
}
</style>
<div class="masked" >
<h1>→css3文字渐变动画效果 >></h1>
</div>
说明:
-webkit-text-fill-color: transparent;(这里必须填充透明颜色,这样渐变的颜色才会填充到文字上面,去掉这个或者填充别的颜色,效果不明显)
检索或设置对象中的文字填充颜色,
2.
.slideShine{
background:#871317 -webkit-linear-gradient(left,#561214,#febaf7 50%,#ff0 90%,#561214) no-repeat 0 0;
background-size:20% 100%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 36px;
text-align: center;
font-weight: bold;
text-decoration: underline;
}
.slideShine {-webkit-animation: slideShine 4s linear infinite;animation: slideShine 4s linear infinite;}
@-webkit-keyframes slideShine {
0% {
background-position: 0 0;
}
100% {
background-position: 100% 100%;
}
}
@keyframes slideShine {
0% {background-position: 0 0; }
100% {background-position: 100% 100%; }
}
<p class="slideShine" >→css3文字渐变动画效果 >></p>
3.跟第2个例子差不多,多给了一个背景颜色,从局部到全局渐变
.text{position: relative;width: 57%;max-width:531px ;}.text .mask{position: absolute;width: 100%;height: 95%;top: 0;left: 0;-webkit-mask-image: url(img/text.png);}
.text .mask i{position: absolute;height:100%;width: 20%;left:0;top:0;background:-webkit-linear-gradient(left,#561214,#febaf7 50%,#ff0 90%,#561214) no-repeat 0 0;animation: lightLine1 4s linear infinite;-webkit-animation: lightLine1 4s linear infinite;background-size:100% 100%;}
@keyframes lightLine1{
0%{transform:translateX(0) ;}
100%{transform:translateX(500%);}
}@-webkit-keyframes lightLine1{
0%{-webkit-transform:translateX(0) ;}
100%{-webkit-transform:translateX(500%) ;}
}
<div class="text" style="margin: 150px auto;">
<img src="img/text.png" />
<div class="mask"><i></i></div>
</div>
4.实现多颜色文字的渐变
.text2{position: relative;width: 63%;max-width:586px ;}.text2 .mask{position: absolute;width: 100%;height: 95%;top: 0;left: 1px;-webkit-mask-image: url(img/text3.png);} .text2 .mask i{position: absolute;height:100%;width: 20%;left:0;top:0;background:-webkit-linear-gradient(left,#561214,#febaf7 50%,#ff0 90%,#561214) no-repeat 0 0;animation: lightLine2 4s linear infinite;-webkit-animation: lightLine2 4s linear infinite;background-size:100% 100%;}
@keyframes lightLine2{
0%{transform:translateX(0) ;}
100%{transform:translateX(420%);}
}
@-webkit-keyframes lightLine2{
0%{-webkit-transform:translateX(0) ;}
100%{-webkit-transform:translateX(420%) ;}
}
<div class="text2" style="margin: 150px auto;">
<img src="img/text3.png" />
<div class="mask"><i></i></div> </div>