【问题标题】:Improve css text animation with heading and list使用标题和列表改进 css 文本动画
【发布时间】:2021-12-07 14:50:49
【问题描述】:

这是我迄今为止编写的代码Codepen

可以忽略背景图片和其他元素。只需要获取标题的动画(即黄色)和右下方的列表。关于如何改进这一点的任何想法?

body {
  background-color: purple;
}

h1 {
  text-align: center;
  text-transform: uppercase;
  background-color: transparent;
  color: yellow;
  width: auto;
  transform: translate3d(0, 200px, 0);
  font-size: 42px;
  line-height: 48px;
}

h1 span {
  opacity: 0;
  display: inline-block;
  transform: translateY(10px);
}

ul {
  list-style: none;
  margin: 50px auto 0 auto;
  padding: 0;
  width: 300px;
  opacity: 0;
}

ul li {
  list-style: none;
  padding: 15px;
  border: solid 1px #fff;
  margin-bottom: 10px;
  border-radius: 15px;
  cursor: pointer;
  color: #fff;
  transition: all 0.5s ease;
}

ul li:hover {
  background-color: #fff;
  color: #333;
}

@keyframes slideUpHeading {
  from {
    transform: translate3d(0, 200px, 0);
    font-size: 42px;
    line-height: 48px;
  }
  to {
    font-size: 24px;
    line-height: 30px;
    transform: translate3d(0, 0, 0);
  }
}

.slideUpHeading {
  animation-name: slideUpHeading;
  animation-delay: 2s;
  animation-duration: 0.6s;
  transform-origin: center bottom;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(1, 1, 2, 2);
}

@keyframes slideUpText {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slideUpText {
  animation-name: slideUpText;
  animation-duration: 0.6s;
  transform-origin: center bottom;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0.17, 0.88, 0.32, 1.5);
}

.animation_delay1 {
  animation-delay: 0.2s;
}

.animation_delay2 {
  animation-delay: 0.45s;
}

.animation_delay3 {
  animation-delay: 0.9s;
}

.animation_delay4 {
  animation-delay: 1.2s;
}

@keyframes slideUpList {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slideUpList {
  animation-name: slideUpList;
  animation-duration: 0.6s;
  animation-delay: 2.65s;
  transform-origin: center bottom;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0.17, 0.88, 0.32, 1.2);
}
<h1 class="slideUpHeading">
  <span class="slideUpText animation_delay1">Lorem</span><br>
  <span class="slideUpText animation_delay2">ipsum</span><br>
  <span class="slideUpText animation_delay3">dolor sit</span><br>
  <span class="slideUpText animation_delay4">amet</span>
</h1>

<ul class="slideUpList">
  <li>consectetur adipiscing elit</li>
  <li>consectetur adipiscing elit</li>
  <li>consectetur adipiscing elit</li>
  <li>consectetur adipiscing elit</li>
</ul>

【问题讨论】:

    标签: css animation css-animations css-transforms


    【解决方案1】:

    除了底部列表动画延迟之外,一切看起来都不错。我已经调整了它以及所有动画持续时间.. 看看。

    body {
      background-color: purple;
      font-family: 'Archivo Black', sans-serif;
    }
    
    h1 {
      text-align: center;
      text-transform: uppercase;
      background-color: transparent;
      color: yellow;
      width: auto;
      transform: translate3d(0, 200px, 0);
      font-size: 42px;
      line-height: 48px;
    }
    
    h1 span {
      opacity: 0;
      display: inline-block;
      transform: translateY(10px);
    }
    
    ul {
      list-style: none;
      margin: 50px auto 0 auto;
      padding: 0;
      width: 300px;
      opacity: 0;
    }
    
    ul li {
      list-style: none;
      padding: 15px;
      border: solid 1px #fff;
      margin-bottom: 10px;
      border-radius: 15px;
      cursor: pointer;
      color: #fff;
      transition: all 0.5s ease;
    }
    
    ul li:hover {
      background-color: #fff;
      color: #333;
    }
    
    @keyframes slideUpHeading {
      from {
        transform: translate3d(0, 200px, 0);
        font-size: 42px;
        line-height: 48px;
      }
      to {
        font-size: 24px;
        line-height: 30px;
        transform: translate3d(0, 0, 0);
      }
    }
    
    .slideUpHeading {
      animation-name: slideUpHeading;
      animation-delay: 2s;
      animation-duration: 0.4s; /* It was 0.6s */
      transform-origin: center bottom;
      animation-fill-mode: both;
      animation-timing-function: cubic-bezier(1, 1, 2, 2);
    }
    
    @keyframes slideUpText {
      from {
        opacity: 0;
        transform: translateY(10px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    
    .slideUpText {
      animation-name: slideUpText;
      animation-duration: 0.4s; /* It was 0.6s */
      transform-origin: center bottom;
      animation-fill-mode: both;
      animation-timing-function: cubic-bezier(0.17, 0.88, 0.32, 1.5);
    }
    
    .animation_delay1 {
      animation-delay: 0.2s;
    }
    
    .animation_delay2 {
      animation-delay: 0.45s;
    }
    
    .animation_delay3 {
      animation-delay: 0.9s;
    }
    
    .animation_delay4 {
      animation-delay: 1.2s;
    }
    
    @keyframes slideUpList {
      from {
        opacity: 0;
        transform: translateY(50px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    
    .slideUpList {
      animation-name: slideUpList;
      animation-duration: 0.4s; /* It was 0.6s */
      animation-delay: 2.20s; /* It was 2.65s */
      transform-origin: center bottom;
      animation-fill-mode: both;
      animation-timing-function: cubic-bezier(0.17, 0.88, 0.32, 1.2);
    }
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Archivo+Black&family=Fredoka+One&display=swap" rel="stylesheet">
    
    <h1 class="slideUpHeading">
    
      <span class="slideUpText animation_delay1">which</span><br>
    
      <span class="slideUpText animation_delay2">statement</span><br>
    
      <span class="slideUpText animation_delay3">best describes</span><br>
    
      <span class="slideUpText animation_delay4">you?</span> <!-- Added : question mark ;) -->
    
    </h1>
    
    <ul class="slideUpList">
      <li>Picking up a new skill</li>
      <li>Picking up a new skill</li>
      <li>Picking up a new skill</li>
      <li>Picking up a new skill</li>
    </ul>

    Play here

    【讨论】:

    • 非常感谢你,现在有了调整,它看起来棒极了!如果没有更多建议,我会选择您的帖子作为答案(:
    • 是的!当然... :)
    • 非常感谢 Nimitt(:请帮助将您的笔帖中的文本更改为“lorem ipsum”。我已选择您的解决方案作为答案。干杯!
    • 我可能需要更多这样的帮助。可以在新帖子中标记您吗?
    • 另外,假设需要第 5 行。那么你认为我应该添加什么样的延迟?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多