javascript - 修改这些简单的加载点
问题描述
这是使用 TweenMax 库创建简单加载点动画的代码。
TweenMax.staggerTo(".dots", 2, {
x: 220,
backgroundColor: 'white',
repeat: -1,
ease: SlowMo.ease.config(0.5, 0.4, false)
}, 0.4);
TweenMax.staggerFrom(".dots", 2, {
opacity: 0,
scale: 0.7,
repeat: -1,
ease: SlowMo.ease.config(0.5, 0.4, true)
}, 0.4);
html {
width: 260px;
height: 32px;
overflow: hidden;
}
body {
background-color: transparent;
text-align: center;
padding: 50px;
}
.container {
background-color: transparent;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.dots {
position: absolute;
width: 1em;
height: 1em;
border-radius: 50%;
background-color: #d0c9d8;
opacity: 1;
left: -120px;
}
.link {
position: absolute;
bottom: 20px;
right: 30px;
color: white;
font-size: 40px;
text-decoration: none;
}
<div class="container">
<div class="dots"></div>
<div class="dots"></div>
<div class="dots"></div>
<div class="dots"></div>
<div class="dots"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
如您所见,有 5 个点正在动画。但我想将点数减少到 3。
删除 2 个 div 会在即将到来的动画点和正在淡出的动画点之间创建一个很长的空间......
解决方案
通过删除 2 div
s 并将TweenMax
代码更新为:
// Change ease:SlowMo.ease.config Power from 0.4 to 0.6
// Change stagger from 0.4 to 0.66
TweenMax.staggerTo(".dots",2,{x:220,backgroundColor:'white',repeat:-1,ease:SlowMo.ease.config(0.5,0.6,false)},0.66);
TweenMax.staggerFrom(".dots",2,{opacity:0,scale:0.7,repeat:-1,ease:SlowMo.ease.config(0.5,0.6,true)},0.66);
您可以通过 3 分获得类似的结果:
TweenMax.staggerTo(".dots", 2, {
x: 220,
backgroundColor: 'white',
repeat: -1,
ease: SlowMo.ease.config(0.5, 0.6, false)
}, 0.66);
TweenMax.staggerFrom(".dots", 2, {
opacity: 0,
scale: 0.7,
repeat: -1,
ease: SlowMo.ease.config(0.5, 0.6, true)
}, 0.66);
html {
width: 260px;
height: 32px;
overflow: hidden;
}
body {
background-color: transparent;
text-align: center;
padding: 50px;
}
.container {
background-color: transparent;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.dots {
position: absolute;
width: 1em;
height: 1em;
border-radius: 50%;
background-color: #d0c9d8;
opacity: 1;
left: -120px;
}
.link {
position: absolute;
bottom: 20px;
right: 30px;
color: white;
font-size: 40px;
text-decoration: none;
}
<div class="container">
<div class="dots"></div>
<div class="dots"></div>
<div class="dots"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
推荐阅读
- c# - 来自多个列和表的 linq 最大日期
- html - 当伪选择器应用负边距时,两个元素(块和内联)显示差异
- angular - 无法使用 rxjs 将 firebase 文档映射到总数
- azure-devops - 我们可以将数据从 azure 文件共享复制到 azure 工件吗
- c# - C#,过滤自定义属性属性值
- javascript - 如何根据 php 中另一个下拉列表中的选择自动填充下拉列表?
- python - 如何避免 Pandas 中的自动舍入
- python - 使用 List Comprehension 在 pandas DataFrame 中创建新列
- c - 使用 g_timeout_add 并更新 GUI
- r - R markdown 中的 grid.arrange 和 ggplots 列表