anime.js - 为什么anime.js不适用于跨度元素
问题描述
我正在尝试使用anime.js为标题中的每个字母设置动画,方法是将标题的每个字母放入一个跨度中。但由于某种原因,我无法为跨度设置动画。为什么会发生这种情况,我该如何解决?
索引.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Header anime animation</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<header>
<h1 id="mainheader">
<span class="header-text" id="f">f</span><span class="header-text" id="o-1">o</span><span class="header-text" id="o-2">o</span>
</h1>
</header>
</div>
<script src="https://unpkg.com/animejs@3.2.1/lib/anime.min.js"></script>
<script src="script.js"></script>
</body>
</html>
样式.css
div#wrapper {
height: 90vh;
width: 100%;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1#mainheader {
position: relative;
top: 50px;
}
脚本.js
anime({
targets: '.header-text',
translateY: -50,
duration: 1000,
delay: anime.stagger(100),
easing: "easeInOutExpo",
autoplay: true
})
解决方案
这是因为 span 元素是内联元素,但anime.js 仅适用于display: block
or display: inline-block
。所以在 style.css 中,只需添加
span.header-text {
display: inline-block
}
推荐阅读
- linux - 磁盘满日志/nginx¿如何清除?
- python - 尝试将 CSV 数据转换为文献计量图的源-目标格式 (Gephi)
- java - 无缘无故跳过我的登录活动
- visual-studio-code - 使用 API 以编程方式获取 Visual Studio 代码片段范围
- python - 使用 anaconda 提示创建新的 scrapy 项目时出错
- html - 水平导航背景颜色中途停止
- python - 使用具有大量类别的附加列在条形图中绘制
- rest - REST API 设计 - 私有资源字段的最佳实践
- sql - 分组此 SQL 查询的问题
- reactjs - 使 TypeScript 函数接受 Redux 连接组件