效果预览

按下右侧的“点击预览”按钮可以在当前页面预览,点击链接可以全屏预览。

https://codepen.io/comehope/pen/gKxyWo

可交互视频

此视频是可以交互的,你可以随时暂停视频,编辑视频中的代码。

请用 chrome, safari, edge 打开观看。

https://scrimba.com/p/pEgDAM/cg48mty

源代码下载

每日前端实战系列的全部源代码请从 github 下载:

https://github.com/comehope/front-end-daily-challenges

代码解读

定义 dom,容器中包含一个圆环和3个小球:

<div class="container">
<div class="ring"></div>
<div class="spheres">
<span class="sphere"></span>
<span class="sphere"></span>
<span class="sphere"></span>
</div>
</div>

居中显示:

body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: darkslategray;
}

改变盒模型:

* {
box-sizing: border-box;
}

画出圆环:

.container {
position: relative;
font-size: 20px;
} .ring {
position: relative;
width: 10em;
height: 10em;
border: 1.5em solid paleturquoise;
border-radius: 50%;
}

在圆环的左上方画出一个小球:

.sphere {
position: absolute;
top: -20%;
left: -20%;
} .sphere::after {
content: '';
position: absolute;
width: 3em;
height: 3em;
background-color: lightseagreen;
border-radius: 50%;
}

让小球在圆环的左上方盘旋:

.sphere {
width: 80%;
height: 80%;
animation: rotate 1.5s linear infinite;
} @keyframes rotate {
to {
transform: rotate(360deg);
}
}

让小球的圆环的上下穿梭:

.ring {
z-index: 2;
} .sphere {
animation:
rotate 1.5s linear infinite,
overlapping 1.5s linear infinite;
} @keyframes overlapping {
to {
z-index: 2;
}
}

通过设置动画延时,制造 3 个小球同时盘旋的效果:

.sphere:nth-child(2) {
animation-delay: -0.5s;
} .sphere:nth-child(3) {
animation-delay: -1s;
}

最后,让容器转动起来,制造小球围绕圆环盘旋的效果:

.container {
animation: rotate 5s linear infinite;
}

大功告成!

最新文章

  1. APUE1
  2. 贪心 Codeforces Round #301 (Div. 2) B. School Marks
  3. 安卓学习笔记---Activity
  4. Android 横屏时禁止输入法全屏
  5. class-dump-z下载地址
  6. Java基础知识强化之IO流笔记09:File类功能
  7. Duanxx的STM32学习:STM32命名规则
  8. linux查看与开启ssh
  9. Kraken.js!
  10. oracle常用高级sql---1
  11. Android中用友盟实现QQ的第三方登录
  12. factorOne cannot be&amp;nb…
  13. 201521123069 《Java程序设计》 第12周学习总结
  14. windows下pip安装python模块时报错
  15. FNV算法实战
  16. kali linux 使用笔记本快捷键调节音量
  17. UML序列图参考资料
  18. SQL练习题-50道SQL练习题及答案与详细分析
  19. jquery中的 deferred之 when (三)
  20. Wyn BI的机会在哪里:越靠近消费者的行业,比如零售、文娱和金融,信息化投入越大 ZT

热门文章

  1. VMware 三种网络配置解释
  2. day09-正侧表达式
  3. linux文件系统与链接
  4. HGNC
  5. ArcGIS自定义坐标变换中的方法说明
  6. HDU1166 敌兵布阵 [线段树模板]
  7. python——删除列表中的元素
  8. Mr.Yu
  9. JVM组成与作用
  10. 使用Spring AOP 实现日志管理(简单教程)