css3闪入-css3中实现文字闪烁效果的三种显示方法

2024-04-22 0 8,444 百度已收录

文字闪烁效果1:

通过改变透明度,文字逐渐闪烁效果如下:

文字闪烁渐变效果:

文字闪烁:闪烁效果
.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; }

如果不需要渐变闪烁效果css3闪入,我们可以在关键帧动画中定义不透明度值50%和50.1%。 如下:

@-webkit-keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 1; }
    50.01% { opacity: 0; }
    100% { opacity: 0; }
}

这样的治疗效果:

文字不逐渐闪烁:闪烁的效果

文字闪烁效果二:

通过设置text-shadow的值css3闪入,实现文字阴影闪烁的效果。 效果如下:

闪烁效果

代码如下所示:

闪烁效果
.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} }

文字闪烁效果三:

使用背景图片或背景渐变来实现文字颜色闪烁的效果。 效果如下:

闪烁效果

代码如下所示:

闪烁效果
  
    .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;
		}
	}

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 css3 css3闪入-css3中实现文字闪烁效果的三种显示方法 https://www.wkzy.net/game/200601.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务