
原文地址:https://segmentfault.com/a/1190000015270808#articleHeader0
感想: 动画效果 + ::before + 2D转换
HTML code:
<div class="loader">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
CSS code:
html, body {
margin:;
padding:;
}
body{
/* height: 100% ; 会有不一样的效果,唉 */
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
/* 画出小球的挂线 */
.loader{
position: absolute;
display: flex;
justify-content: space-between;
align-items: flex-start; /* 这是默认值 */
width: 12em;
font-size: 10px;
/* 画出牛顿摆的挂架 */
border-color: black;
border-style: solid;
border-width: 0.4em 0.1em 4em 0.1em;
/* border: 0.4em 0.1em 4em 0.1em solid black; 这个不行 */
padding: 0 4em 2em 4em;
}
.loader span{
position: relative;
width: 0.2em;
height: 10em;
background-color: black;
transform-origin: top;
}
/* 让最左侧的摆线晃动 */
.loader span:first-child{
animation: moving-up 0.75s cubic-bezier(0.215, 0.61, 0.355, 1) infinite alternate;
--direction:;
}
.loader span:last-child{
/* cubic-bezier(n,n,n,n) 函数定义速度曲线 在 cubic-bezier 函数中自己的值。可能的值是从 0 到 1 的数值。 */
animation: moving-up 0.75s cubic-bezier(0.215, 0.61, 0.355, 1) infinite alternate-reverse;
--direction: -1;
}
@keyframes moving-up{
0%{
transform: rotate(0deg);
}
50%{
transform: rotate(0deg);
}
100%{
transform: rotate(calc(45deg * var(--direction)));
}
}
/* 画出小球 */
.loader span::before{
content: '';
width: 3em;
height: 3em;
border-radius: 50%;
position: absolute;
left: -1.4em;
bottom:;
background-color: black;
}