网站链接: 我爱捣鼓
当前位置: 首页 > 前端开发 > css

css实现文字渐隐渐现炫酷效果

2022/5/7 21:23:15

一行文字实现渐隐渐现的效果使用flash是很容易实现的,但如何通过css去实现这种文字炫酷的效果?<html><head> <meta charset="UTF-8"> <link rel="apple-touch-icon" type="image/png" href="https://cpwe…

        一行文字实现渐隐渐现的效果使用flash是很容易实现的,但如何通过css去实现这种文字炫酷的效果?

image.png

<html>
<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" type="image/png"
    href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png">
  <meta name="apple-mobile-web-app-title" content="CodePen">
  <link rel="shortcut icon" type="image/x-icon"
    href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico">
  <link rel="mask-icon" type="image/x-icon"
    href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg"
    color="#111">
  <title>css实现文字渐隐渐现炫酷效果www.woaidaogu.com</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
  <style>
    html,
    body {
      width: 100%;
      height: 100%;
      display: flex;
      overflow: hidden;
    }
    .button {
      top: 0;
      left: 0;
      width: 120px;
      height: 64px;
      line-height: 64px;
      text-align: center;
      border: 1px solid #eee;
      cursor: pointer;
      transition: 0.3s all;
      z-index: 1;
    }
    .button:hover {
      background: #eee;
    }
    .button:hover~.g-wrap {
      content: "";
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      transition: 0.3s background linear;
      background: rgba(0, 0, 0, 0.5);
    }
    p {
      position: relative;
      margin: 50px auto;
      width: 500px;
      height: 250px;
      font-size: 22px;
      line-height: 1.5;
      overflow: hidden;
      z-index: 2;
    }
    p span {
      position: relative;
      display: inline-block;
      opacity: 0;
      transform: translateY(15px) translateZ(0);
      transition-property: transform, opacity;
      transition-duration: 0.3s, 0.2s;
      transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1), linear;
    }
    .button:hover~p span {
      opacity: 1;
      color: #ddd;
      transform: translateY(0) translateZ(0);
      transition-property: transform, opacity;
      transition-duration: 1s, 0.2s;
      transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1), linear;
    }
    p span:after,
    p span:before {
      position: absolute;
      content: attr(data-text);
      top: 0;
      left: 0;
      z-index: 1;
      transform: translateZ(0);
      will-change: opacity;
    }
    p span:after {
      color: #e62541;
      transition-property: opacity;
      transition-duration: 0.1s;
      transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
    }
    .button:hover~p span:after {
      opacity: 0;
      transition-property: opacity;
      transition-duration: 0.4s;
      transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
    }
    p span:nth-child(1) {
      transition-delay: 0.04s;
    }
    p span:nth-child(1)::after {
      transition-delay: 0.24s;
    }
    p span:nth-child(2) {
      transition-delay: 0.08s;
    }
    p span:nth-child(2)::after {
      transition-delay: 0.28s;
    }
    p span:nth-child(3) {
      transition-delay: 0.12s;
    }
    p span:nth-child(3)::after {
      transition-delay: 0.32s;
    }
    p span:nth-child(4) {
      transition-delay: 0.16s;
    }
    p span:nth-child(4)::after {
      transition-delay: 0.36s;
    }
    p span:nth-child(5) {
      transition-delay: 0.2s;
    }
    p span:nth-child(5)::after {
      transition-delay: 0.4s;
    }
    p span:nth-child(6) {
      transition-delay: 0.24s;
    }
    p span:nth-child(6)::after {
      transition-delay: 0.44s;
    }
    p span:nth-child(7) {
      transition-delay: 0.28s;
    }
    p span:nth-child(7)::after {
      transition-delay: 0.48s;
    }
    p span:nth-child(8) {
      transition-delay: 0.32s;
    }
    p span:nth-child(8)::after {
      transition-delay: 0.52s;
    }
    p span:nth-child(9) {
      transition-delay: 0.36s;
    }
    p span:nth-child(9)::after {
      transition-delay: 0.56s;
    }
    p span:nth-child(10) {
      transition-delay: 0.4s;
    }
    p span:nth-child(10)::after {
      transition-delay: 0.6s;
    }
    p span:nth-child(11) {
      transition-delay: 0.44s;
    }
    p span:nth-child(11)::after {
      transition-delay: 0.64s;
    }
    p span:nth-child(12) {
      transition-delay: 0.48s;
    }
    p span:nth-child(12)::after {
      transition-delay: 0.68s;
    }
    p span:nth-child(13) {
      transition-delay: 0.52s;
    }
    p span:nth-child(13)::after {
      transition-delay: 0.72s;
    }
    p span:nth-child(14) {
      transition-delay: 0.56s;
    }
    p span:nth-child(14)::after {
      transition-delay: 0.76s;
    }
    p span:nth-child(15) {
      transition-delay: 0.6s;
    }
    p span:nth-child(15)::after {
      transition-delay: 0.8s;
    }
    p span:nth-child(16) {
      transition-delay: 0.64s;
    }
    p span:nth-child(16)::after {
      transition-delay: 0.84s;
    }
    p span:nth-child(17) {
      transition-delay: 0.68s;
    }
    p span:nth-child(17)::after {
      transition-delay: 0.88s;
    }
    p span:nth-child(18) {
      transition-delay: 0.72s;
    }
    p span:nth-child(18)::after {
      transition-delay: 0.92s;
    }
    p span:nth-child(19) {
      transition-delay: 0.76s;
    }
    p span:nth-child(19)::after {
      transition-delay: 0.96s;
    }
    p span:nth-child(20) {
      transition-delay: 0.8s;
    }
    p span:nth-child(20)::after {
      transition-delay: 1s;
    }
  </style>
  <script>
    if (document.location.search.match(/type=embed/gi)) {
      window.parent.postMessage("resize", "*");
    }
  </script>
</head>
<body translate="no">
  <div>Button</div>
  <div></div>
  <p><span data-text="Lorem">Lorem</span> <span data-text="ipsum">ipsum</span> <span data-text="dolor">dolor</span>
    <span data-text="sit">sit</span> <span data-text="amet">amet</span> <span data-text="consectetur">consectetur</span>
    <span data-text="adipisicing">adipisicing</span> <span data-text="elit.">elit.</span> <span
      data-text="Mollitia">Mollitia</span> <span data-text="nostrum">nostrum</span> <span
      data-text="placeat">placeat</span> <span data-text="consequatur">consequatur</span> <span
      data-text="deserunt">deserunt</span> <span data-text="velit">velit</span> <span data-text="ducimus">ducimus</span>
    <span data-text="possimus">possimus</span> <span data-text="commodi">commodi</span> <span
      data-text="temporibus">temporibus</span> <span data-text="debitis">debitis</span> <span
      data-text="quam.">quam.</span></p>
  <script
    src="https://cpwebassets.codepen.io/assets/editor/iframe/iframeRefreshCSS-4793b73c6332f7f14a9b6bba5d5e62748e9d1bd0b5c52d7af6376f3d1c625d7e.js"></script>
  <div id="xl_chrome_ext_{4DB361DE-01F7-4376-B494-639E489D19ED}" style="display: none;">
    <div></div>
    <a id="xl_chrome_ext_download" href="javascript:;">下载视频</a>
    <a id="xl_chrome_ext_close" href="javascript:;"></a>
  </div>
</body>
</html>

        查看在线实例

        通过以上内容我们知道了css如何实现文字渐隐渐现炫酷效果?感谢您访问“我爱捣鼓(www.woaidaogu.com)”网站的内容,希望对大家有所帮助!引用本文内容时,请注明出处!谢谢合作!

相关资讯

  • 设置英文首字母大写的css属性是什么?

    设置CSS text-transform 的属性为capitalize就可以实现英文首字母大写。 定义和用法  text-transform 属性控制文本的大小写。 属性值 值 描 述 none 默认。定义带有小写字…

    2021/7/14 20:35:17
  • 只让页面显示横滚动条,不显示竖滚动条如何实现?

    只让页面显示横滚动条,不显示竖滚动条的方法其实很简单,主要用到body的两个css属性 overflow和 overflow-y,如下所示:body { overflow:scroll; overflow-y:hidden;}

    2021/2/28 21:45:25
  • 网页的滚动条样式可以修改吗?如何修改?

    网页的滚动条样式可以修改的,主要是使用css来控制那如何修改呢?如下代码:<div class="inner"> <div class="innerbox"> <p style="height:200px;">这是内容111</p> <p style="hei…

    2021/2/28 21:15:24
  • css如何实现6张图片均匀排列在一行?

    css部分如下:img{width:120px; height:80px;float:left;margin-right:16px;}.img3{margin-right:0;}html部分如下:<img src="images/001.jpg" /><img src="images/002.jpg" /><img src="images/003.jpg" /><img src=…

    2021/2/28 21:10:01