1. 程式人生 > 其它 >文字閃爍特效 html+css

文字閃爍特效 html+css

技術標籤:前端csshtmlcss3前端

上效果先:

在這裡插入圖片描述

先言:

看過我文章可以知道,這東西似曾相識~ ╭(●`∀´●)╯確實,這個和我另一篇文章“文字點閃特效”原理是差不多的

實現:

1.定義html標籤:

<h1>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <
span
>
</span> <span></span> <span></span> <span></span> <span></span> </h1>

2.文字的基本樣式,大小顏色等:

 h1{
            font-family: 'fangsong';
            font-size: 6em;
            color: transparent;
} span{ display: table-cell; animation: san 3s linear infinite; }

display: table-cell;此元素會作為一個表格單元格顯示(類似 和 )
color: transparent;文字顏色透明

3.文字發亮的效果,就閃一下然後就又會(20%-80%的時候)變透明:

 @keyframes san{
            0%,100%{
                color: rgb(255, 255, 255);         
                text-shadow
: 0 0 5px rgb(1, 231, 247), 0 0 15px rgb(1, 231, 247), 0 0 25px rgb(1, 231, 247), 0 0 50px rgb(1, 231, 247), 0 0 80px rgb(1, 231, 247), 0 0 120px rgb(1, 231, 247), 0 0 160px rgb(1, 231, 247), 0 0 200px rgb(1, 231, 247), 0 0 300px rgb(1, 231, 247), 0 0 400px rgb(1, 231, 247), 0 0 500px rgb(1, 231, 247); } 20%,80%{ color: transparent; text-shadow: none; } }

text-shadow:是給它加陰影,寫了很多行是為了陰影更亮;

4.製造時間差,讓不同的時間不同的文字亮;

 h1 span:nth-child(1){
            animation-delay:0s;
        }
        h1 span:nth-child(2){
            animation-delay:0.1s;
        } 
        h1 span:nth-child(3){
            animation-delay:0.2s;
        }
        h1 span:nth-child(4){
            animation-delay:0.3s;
        }
        h1 span:nth-child(5){
            animation-delay:0.4s;
        }
        h1 span:nth-child(6){
            animation-delay:0.5s;
        }
        h1 span:nth-child(7){
            animation-delay:0.6s;
        }
        h1 span:nth-child(8){
            animation-delay:0.7s;
        }
        h1 span:nth-child(9){
            animation-delay:0.8s;
        }
        h1 span:nth-child(10){
            animation-delay:0.9s;
        }

animation-delay 等待多少秒,然後才開始動畫;

完整程式碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>北極光之夜。</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body{
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: rgb(0, 0, 0);
        }
        h1{
            font-family: 'fangsong';
            font-size: 6em;
            color: transparent;
        }
        span{
           display: table-cell;
           animation: san 3s linear infinite;
        }
        h1 span:nth-child(1){
            animation-delay:0s;
        }
        h1 span:nth-child(2){
            animation-delay:0.1s;
        } 
        h1 span:nth-child(3){
            animation-delay:0.2s;
        }
        h1 span:nth-child(4){
            animation-delay:0.3s;
        }
        h1 span:nth-child(5){
            animation-delay:0.4s;
        }
        h1 span:nth-child(6){
            animation-delay:0.5s;
        }
        h1 span:nth-child(7){
            animation-delay:0.6s;
        }
        h1 span:nth-child(8){
            animation-delay:0.7s;
        }
        h1 span:nth-child(9){
            animation-delay:0.8s;
        }
        h1 span:nth-child(10){
            animation-delay:0.9s;
        }
        @keyframes san{
            0%,100%{
                color: rgb(255, 255, 255);         
                text-shadow: 0 0 5px rgb(1, 231, 247),
                            0 0 15px rgb(1, 231, 247),
                            0 0 25px rgb(1, 231, 247),
                            0 0 50px rgb(1, 231, 247),
                            0 0 80px rgb(1, 231, 247),
                            0 0 120px rgb(1, 231, 247),
                            0 0 160px rgb(1, 231, 247),
                            0 0 200px rgb(1, 231, 247),
                            0 0 300px rgb(1, 231, 247),
                            0 0 400px rgb(1, 231, 247),
                            0 0 500px rgb(1, 231, 247);
            }
            20%,80%{
               color: transparent;
               text-shadow: none;
            }
           
        }
    </style>
</head>
<body>
    <h1>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        
    </h1>
</body>
</html>

總結:

新的一年,新的希望!