效果预览

在线演示

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

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

可交互视频

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

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

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

源代码下载

本地下载

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

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

代码解读

定义 dom,容器中包含 2 个元素,分别代表怪兽的身体和眼睛:

<div class="monster">
<span class="body"></span>
<span class="eyes"></span>
</div>

设置背景色:

body {
margin: 0;
height: 100vh;
background-color: black;
}

设置前景色:

.monster {
width: 100vw;
height: 50vh;
background-color: lightcyan;
}

画出怪兽的身体:

.monster {
position: relative;
} .body {
position: absolute;
width: 32vmin;
height: 32vmin;
background-color: teal;
border-radius: 43% 40% 43% 40%;
bottom: calc(-1 * 32vmin / 2 - 4vmin);
}

定义怪兽眼睛所在的容器:

.eyes {
width: 24vmin;
height: 5vmin;
position: absolute;
bottom: 2vmin;
left: calc(32vmin - 24vmin - 2vmin);
}

用伪元素画出怪兽的眼睛:

.eyes::before,
.eyes::after {
content: '';
position: absolute;
width: 5vmin;
height: 5vmin;
border: 1.25vmin solid white;
box-sizing: border-box;
border-radius: 50%;
} .eyes::before {
left: 4vmin;
} .eyes::after {
right: 4vmin;
}

为怪兽定义轻轻跳起的动画,结合后面的动画效果,让它具有果冻的弹性:

.body {
animation:
bounce 1s infinite alternate;
} @keyframes bounce {
to {
bottom: calc(-1 * 32vmin / 2 - 2vmin);
}
}

让怪兽的身体转动起来:

@keyframes wave {
to {
transform: rotate(360deg);
}
}

让怪兽徘徊行走:

.monster {
overflow: hidden;
} .body {
left: -2vmin;
animation:
wander 5s linear infinite alternate,
wave 3s linear infinite,
bounce 1s infinite alternate;
} .eyes {
animation: wander 5s linear infinite alternate;
} @keyframes wander {
to {
left: calc(100% - 32vmin + 2vmin);
}
}

最后,让怪兽的眼睛眨一眨:

.eyes::before,
.eyes::after {
animation: blink 3s infinite linear;
} @keyframes blink {
4%, 10%, 34%, 40% {
transform: scaleY(1);
} 7%, 37% {
transform: scaleY(0);
}
}

大功告成!

原文地址:https://segmentfault.com/a/1190000015484852

最新文章

  1. for循环递归树
  2. Eclipse右下角一直提示Computing additional info解决办法
  3. php的Excel相关操作
  4. epoll的使用
  5. Elasticsearch从0.90到1.2的不兼容变化-系统和设置
  6. Java API ——包装类
  7. linux vmstat使用说明
  8. JAVA FILE or I/O学习 - File学习
  9. Javascript常用函数收集(不定期更新)
  10. javascript alert,confirm,prompt弹框用法
  11. Zip操作的工具类
  12. Eclipse开发前,常用设置
  13. [Python] Python 学习 - 可视化数据操作(一)
  14. C#控件——批量化隐藏或显示同类型控件
  15. Oracle 11g安装步骤以及Oracle11g创建表空间和用户,并授权
  16. 确保你想要修改的char*是可以修改的
  17. bzoj5016 一个简单的询问
  18. 第三方网站返回hybrid app H5页面缓存问题应对策略
  19. Kubernetes集群的安装部署
  20. aspnetcore 认证相关类简要说明二

热门文章

  1. hibernate的.hbm.xml文件文件配置属性详解
  2. 基于ZooKeeper的服务注册中心
  3. local unversioned, incoming add upon update问题
  4. Storm-源码分析-Topology Submit-Supervisor
  5. Python中的推导式(列表推导式、字典推导式、集合推导式)
  6. 用Python爬虫爬取广州大学教务系统的成绩(内网访问)
  7. vue中获取客户端IP地址(不需要额外引入三方文件)
  8. git学习------>从SVN迁移到Git之后,项目开发代码继续在SVN提交,如何同步迁移之后继续在SVN提交的代码到Git?
  9. Python3.6编译安装以及python开发之virtualenv与virtualenvwrapper
  10. 具体解释linux下的串口通讯开发