• CSS实现 文字逐行显示&文字逐个显示


    一,文字逐行显示

    HTML:

    <div className="LetterToFuture__homeTexts">
         {Array.from(new Array(5)).map((_, idx) => (
           /* eslint-disable-next-line react/no-array-index-key */
              <div key={idx} className="LetterToFuture__homeText" />
          ))}
     </div>

    CSS:由于字体效果比较特殊,所以每行文字采用的是图片

    $fadeInDur: 1500ms;
    $textWidth: "231px", "124px", "97px", "96px", "213px";
    
    .LetterToFuture__homeTexts {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-start;
    }
    
    .LetterToFuture__homeText {
      background: url(../../images/text_1.png) no-repeat center center / 100% 100%;
      height: 15px;
      margin-top: 25px;
      animation: slide-up-in #{$fadeInDur} ease-out both  1/*infinite*/;
    
      &:nth-child(1) {
        margin-top: 15px;
      }
    
      /* 官网的 list.nth 写法 not working - https://stackoverflow.com/questions/53155503/how-to-find-the-scss-index-of-the-element-in-the-list */
      /*@debug list.nth([line1, line2, line3], -1);*/
      /*@debug list.nth(10px 12px 16px, 2);*/
      /*@debug "------------------------------------------------------------------------------------------";*/
      /* 正常 */
      /*@debug nth($textWidth, 1);*/
    
      @for $idx from 1 through 5 {
        &:nth-child(#{$idx}) {
          animation-delay: #{($idx - 1) * $fadeInDur};
          background-image: url(../../images/text_#{$idx}.png);
           #{nth($textWidth, $idx)};
        }
      }
    }
    
    @keyframes slide-up-in {
      0% {
        opacity: 0;
        transform: translate(0, 15px);
      }
    
      100%  {
        opacity: 1;
        transform: translate(0, 0);
      }
    }

    以上实现效果是:每行文字位移由下至上,透明度从0到1,逐渐显示,如果你不想要位移变化,将css里位移相关代码去掉即可。

    二,文字逐个显示

    HTML:

    <div className="WorldBookDayQuestionOne__textWrap">
        {text.split('').map((t, idx) => (
             /* eslint-disable-next-line react/no-array-index-key */
          <span key={idx} className="WorldBookDayQuestionOne__text">
                    {t}
           </span>
         ))}
    </div>

    CSS:

    $fadeInDur: 1500ms;
    
    .WorldBookDayQuestionOne{
     
      &__textWrap {
        width: 150px;
        margin: 0 auto;
        margin-top: 100px;
        background-color: burlywood;
      }
      &__text {
        opacity: 0;
        animation: fade-in #{$fadeInDur} ease-out both  1/*infinite*/;
        @for $idx from 1 through 50 {
          &:nth-child(#{$idx}) {
            animation-delay: #{($idx - 1) * $fadeInDur};
          }
        }
      }
    }
    
    @keyframes fade-in {
      0% {
        opacity: 0;
      }
    
      100%  {
        opacity: 1;
      }
    }

    以上实现效果是:文字透明度由0到1逐个显示,当一行显示不下的时候会自动往下一行折叠,一行显示多少文字取决于父元素容器大小。

  • 相关阅读:
    WebService出错 Maximum message size quota for incoming messages (65536) has been exceeded.已超过传入消息(65536)的最大消息大小配额
    php 获取系统时间
    JavaSctipt 控制网页 前进,后退
    放A片的文件夹的名字
    玩玩独轮车
    3月18日周六骑行三水大旗头村——广东名镇之一
    叫春的猫
    抓紧锻炼身体噢!
    使用Zend Framework中的 Zend_Pdf来创建pdf文档
    虚拟主机示例
  • 原文地址:https://www.cnblogs.com/chenbeibei520/p/16091146.html
Copyright © 2020-2023  润新知