乐趣区

关于html:文字加载特效

代码来自头条号 ’ 前端小智 ’, 侵权删

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title> 文字加载 </title>
  <style>
    /* 思路是
      上面一层文字, 下面一层文字, 应用动画扭转下面文字的宽度

    */
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body{
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: #000;
    }
    h2{
      position: relative;
      font-size: 14vw;
      text-transform: uppercase;
      color: #252839;
      -webkit-text-stroke: 0.3vw #283d52; /* 字体的描边 */
    }
    h2::before{content: attr(data-text);
      position: absolute;
      top: 0;
      left: 0;
      color: #01fe87;
      width: 100%;
      height: 100%;
      -webkit-text-stroke: 0vw #383d52;
      border-right:1px solid #01fe87 ;
      overflow: hidden;
      animation: animate 6s linear infinite;
    }
    @keyframes animate {
      0%, 10%, 100%{width: 0;}
      70%{width: 100%;}
    }
  </style>
</head>
<body>
  <h2 data-text='creative...'>creative...</h2>
</body>
</html>
退出移动版