飞行文本动画效果

效果展示

飞行文本动画效果1.png
飞行文本动画效果2.png
飞行文本动画效果3.png

JavaScript 知识点

  • textContent.replace 方法运用
  • anime.min.js 插件运用

实现整体页面布局

<section>
  <p class="text">
    Lorem ipsum dolor sit amet consectetur, adipisicing elit. Impedit suscipit
    iure explicabo delectus laborum architecto, dolorem ratione beatae vero! Sit
    nobis commodi beatae nemo accusamus eaque repellendus ipsam non molestias.
  </p>
</section>

段落语句拆分成单独的字符

const texts = document.querySelector(".text");
texts.innerHTML = texts.textContent.replace(/\S/g, "<span>$&</span>");

文字样式实现

section .text {
  position: relative;
  text-align: center;
  color: #00cefe;
  margin: 40px;
  max-width: 650px;
}

section .text span {
  position: relative;
  display: inline-block;
}

使用anime.min.js实现动画效果

const animation = anime.timeline({
  targets: ".text span", // 动画执行者
  easing: "easeInOutExpo", // 动画缓冲类型
  loop: true, // 动画重复执行
});

// add 是添加一个动画环节
animation
  .add({
    rotate: function () {
      return anime.random(-360, 360);
    },
    translateX: function () {
      return anime.random(-500, 500);
    },
    translateY: function () {
      return anime.random(-500, 500);
    },
    duration: 5000,
    delay: anime.stagger(20),
  })
  .add({
    rotate: 0,
    translateX: 0,
    translateY: 0,
    duration: 5000,
    delay: anime.stagger(20),
  });

完整代码下载

完整代码下载

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容