CSS3实现文字闪烁效果的多种形式代码
更新:2020-03-31 08:18:31
人气:7538
来源:本站整理
A+
文字闪烁效果一
通过改变透明度来实现文字的渐变闪烁,代码如下:
<div class="main">
文字闪烁:<span class="blink">闪烁效果</span></div><style type="text/css">.main{ color: #666;margin-top: 50px;
}/* 定义keyframe动画,命名为blink */@keyframes blink{
0%{opacity: 1;}
100%{opacity: 0;}
}/* 添加兼容性前缀 */@-webkit-keyframes blink {
0% { opacity: 1; }
100% { opacity: 0; }
}
@-moz-keyframes blink {
0% { opacity: 1; }
100% { opacity: 0; }
}
@-ms-keyframes blink {
0% {opacity: 1; }
100% { opacity: 0;}
}
@-o-keyframes blink {
0% { opacity: 1; }
100% { opacity: 0; }
}/* 定义blink类*/.blink{ color: #dd4814; animation: blink 1s linear infinite;
/* 其它浏览器兼容性前缀 */
-webkit-animation: blink 1s linear infinite; -moz-animation: blink 1s linear infinite; -ms-animation: blink 1s linear infinite; -o-animation: blink 1s linear infinite;
}</style>如果不需要渐变闪烁效果,我们可以在keyframe动画中定义50%,50.1%的opacity的值。如下:
@-webkit-keyframes blink {
0% { opacity: 1; }
50% { opacity: 1; }
50.01% { opacity: 0; }
100% { opacity: 0; }
}文字闪烁效果二
通过设置text-shadow的值,来实现文字阴影闪烁的效果,代码如下:
<div class="box">闪烁效果</div><style>
.box{
font-size: 20px;
color:#4cc134;
margin: 10px; animation: changeshadow 1s ease-in infinite ; /* 其它浏览器兼容性前缀 */
-webkit-animation: changeshadow 1s linear infinite; -moz-animation: changeshadow 1s linear infinite; -ms-animation: changeshadow 1s linear infinite; -o-animation: changeshadow 1s linear infinite;
}
@keyframes changeshadow {
0%{ text-shadow: 0 0 4px #4cc134}
50%{ text-shadow: 0 0 40px #4cc134}
100%{ text-shadow: 0 0 4px #4cc134}
} /* 添加兼容性前缀 */
@-webkit-keyframes changeshadow {
0%{ text-shadow: 0 0 4px #4cc134}
50%{ text-shadow: 0 0 40px #4cc134}
100%{ text-shadow: 0 0 4px #4cc134}
}
@-moz-keyframes changeshadow {
0%{ text-shadow: 0 0 4px #4cc134}
50%{ text-shadow: 0 0 40px #4cc134}
100%{ text-shadow: 0 0 4px #4cc134}
}
@-ms-keyframes changeshadow {
0%{ text-shadow: 0 0 4px #4cc134}
50%{ text-shadow: 0 0 40px #4cc134}
100%{ text-shadow: 0 0 4px #4cc134}
}
@-o-keyframes changeshadow {
0%{ text-shadow: 0 0 4px #4cc134}
50%{ text-shadow: 0 0 40px #4cc134}
100%{ text-shadow: 0 0 4px #4cc134}
}</style>文字闪烁效果三
利用背景图片或者背景渐变,实现文字颜色的闪烁效果,代码如下:
<span class="box">闪烁效果</span><style>
.box{
display: inline-block; font-size: 20px; margin: 10px; background: linear-gradient(left, #f71605, #e0f513);
background: -webkit-linear-gradient(left, #f71605, #e0f513); background: -o-linear-gradient(right, #f71605, #e0f513); -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation:scratchy 0.253s linear forwards infinite; /* 其它浏览器兼容性前缀 */
-webkit-animation:scratchy 0.253s linear forwards infinite; -moz-animation: scratchy 0.253s linear forwards infinite; -ms-animation: scratchy 0.253s linear forwards infinite; -o-animation: scratchy 0.253s linear forwards infinite;
}
@keyframes scratchy {
0% { background-position: 0 0;
}
25% { background-position: 0 0;
}
26% { background-position: 20px -20px;
}
50% { background-position: 20px -20px;
}
51% { background-position: 40px -40px;
}
75% { background-position: 40px -40px;
}
76% { background-position: 60px -60px;
}
99% { background-position: 60px -60px;
}
100% { background-position: 0 0;
}
} /* 添加兼容性前缀 */
@-webkit-keyframes scratchy {
0% { background-position: 0 0;
}
25% { background-position: 0 0;
}
26% { background-position: 20px -20px;
}
50% { background-position: 20px -20px;
}
51% { background-position: 40px -40px;
}
75% { background-position: 40px -40px;
}
76% { background-position: 60px -60px;
}
99% { background-position: 60px -60px;
}
100% { background-position: 0 0;
}
}
@-moz-keyframes scratchy {
0% { background-position: 0 0;
}
25% { background-position: 0 0;
}
26% { background-position: 20px -20px;
}
50% { background-position: 20px -20px;
}
51% { background-position: 40px -40px;
}
75% { background-position: 40px -40px;
}
76% { background-position: 60px -60px;
}
99% { background-position: 60px -60px;
}
100% { background-position: 0 0;
}
}
@-ms-keyframes scratchy {
0% { background-position: 0 0;
}
25% { background-position: 0 0;
}
26% { background-position: 20px -20px;
}
50% { background-position: 20px -20px;
}
51% { background-position: 40px -40px;
}
75% { background-position: 40px -40px;
}
76% { background-position: 60px -60px;
}
99% { background-position: 60px -60px;
}
100% { background-position: 0 0;
}
}
@-o-keyframes scratchy {
0% { background-position: 0 0;
}
25% { background-position: 0 0;
}
26% { background-position: 20px -20px;
}
50% { background-position: 20px -20px;
}
51% { background-position: 40px -40px;
}
75% { background-position: 40px -40px;
}
76% { background-position: 60px -60px;
}
99% { background-position: 60px -60px;
}
100% { background-position: 0 0;
}
}</style>
推荐的文章
随手记
- ● 统信UOS系统如何设置指定时间自动重启系统的方法
- ● 自制(IP或域名)可信任的SSL证书,适用360、chrome等浏览器
- ● windows系统下php无法使用curl怎么办?
- ● 绿联UGREENKVM切换器(分屏器)快捷键丢失解决办法
- ● 统信UOS开机指定网址全屏启动自带浏览器以及屏蔽ALT+F4关闭
- ● xshellSSH连接Linux服务器防止超时退出
- ● php8开启OpenSSL扩展库报错disabledinstallext
- ● 统信系统linux安装php时的报错libxml-2.0>=2.7.6
- ● tidb关闭sql_mode=ONLY_FULL_GROUP_BY模式
- ● windows10如何开机自动运行bat文件
PHP经验分享
- ● PHP批量对TCP服务端指定多个IP非阻塞检查在线状态
- ● python实现TCP服务端持续接收关机、重启指令并输出结果【系列三】
- ● PHP给TCP服务端发送指令【系列二】
- ● PHP判断TCP服务端是否在线【系列一】
- ● PHP判断远程文件是否存在
- ● LINUX下用PHP获取CPU型号、内存占用、硬盘占用等信息代码
- ● PHP代码用UDP方式远程唤醒电脑让计算机开机
- ● apache下php生成验证码图片不能显示
- ● PHP使用AES加密解密示例(无偏移)
- ● Pluginmysql_native_passwordreported:''mysql_native_password'isdeprecate问题








