通過改變透明度來實現文字的漸變閃爍,代碼如下:
<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>點擊查看效果
以上361模板介紹的3中文字閃爍效果主要使用到css3的animation屬性,大家可以直接復制使用,如果還有其他的閃爍效果,可以給361模板投稿哦!!
以上就是html文字閃爍代碼 css3文字閃爍效果 的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持武林網。新聞熱點
疑難解答