html打造动画【系列4】哆啦A梦
我相信每个人的童年都有一个哆啦a梦,一个小小的肚皮里装满了不可思议的哆啦a梦,一个在你无助伤心的时候陪在你身边的哆啦a梦,一个陪你胡思乱想陪你吃铜锣烧的哆啦a梦~今天我们就来画一个我们心中的哆啦a梦吧~
定义哆啦a梦的容器
- 千篇一律先定义一个画哆啦a梦的大容器,确定它的大小和位置。
<!-- 哆啦A梦大容器 -->
<div class="doa"></div>
/*哆啦A梦*/
.doa{position: relative;top: 100px;}
画哆啦a梦的头部(包括脸,脸部包括眼睛和鼻子)
- 头部包含好几块部分:哆啦a梦的脸部和鼻子,脸部又包括两只眼睛,两只眼睛里面还有眼珠和眼白部分,所以会有好几层的dom嵌套,当然基本图形都是由div+border-radius拼凑而成。
- 将画好的各个部位品拼凑到相应的位置上即可。
- 看我前面画的几个图画就知道border-radius是一个非常常用的属性,几乎div的每一次变形都离不开它,其实border-radius的真面目应该是
border-radius: 300px 300px 300px 300px/300px 300px 300px 300px;酱紫的,我们一般不写斜杠后面的内容,斜杠切面是水平长度,斜杠后面是垂直高度,前杠后面默认不写就是水平和垂直大小是一样的。我知道我这样说不够详细,可以参考我鑫神的博客秋月何时了,CSS3 border-radius知多少?,保证你分分钟在老司机的带领下彻底弄懂border-radius,还不快上车?<!-- 头 -->
<div class="head">
<!-- 存放脸部的容器 -->
<div class="face">
<!-- 左眼大圈儿 -->
<div>
<!-- 左眼眼珠(黑色部分) -->
<div>
<!-- 左眼眼白,黑色里面的白色部分 -->
<div></div>
</div>
</div>
<!-- 右眼大圈儿 -->
<div>
<!--右眼眼珠(黑色部分) -->
<div>
<!-- 右眼眼白,黑色里面的白色部分 -->
<div></div>
</div>
</div>
</div>
<!-- 红鼻子部分 -->
<div class="nose">
<!-- 红鼻子里面的白圈儿 -->
<div></div>
</div>
<!-- 红鼻子下面的那根黑线,也属于鼻子部分 -->
<div class="nose1"></div>
</div>
.head{
margin: 0 auto; /*头部定义大小并居中显示*/
width: 400px;
height: 350px;
background: #008ee3; /*头部定义背景颜色*/
position: relative;
border-radius: 50% 50% 25% 25% / 55% 55% 45% 45%; /*头部定义四个方向圆角大小*/
}
.face{
width: 310px; /*脸部定义大小*/
height: 260px;
background: snow; /*脸部定义背景颜色*/
border-radius: 50% 50% 25% 25% / 55% 55% 45% 45%; /*脸部定义四个方向的圆角大小*/
position: relative; /*脸部定义位置,是相对于head的位置*/
top: 90px;
left: 45px;
}
/*左眼眶*/
.face>div:first-child{
width: 80px; /*左眼框定义大小*/
height: 100px;
border-radius: 50%; /*左眼框定义与圆角大小*/
border:2px #000 solid; /*定义外边框*/
background: snow;
float: left; /*为了使左右两个眼睛能在一排显示*/
position: relative; /*位置是相对于face的位置*/
top:-40px;
left: 71px;
z-index: 50;
}
/*右眼眶,画法跟左眼一样*/
.face>div:last-child{
width: 80px;
height: 100px;
border-radius: 50%;
border:2px #000 solid;
background: snow;
float: left;
position: relative;
top:-40px;
left: 71px;
z-index: 50;
}
/*左眼珠1*/
.face>div:first-child div{
width: 20px; /*定义眼珠的大小*/
height: 25px;
background: #000;
border-radius: 50%;
position: absolute; /*定义眼珠的位置,相对于眼眶的位置*/
top: 45px;
left: 60px;
}
/*左瞳孔*/
.face>div:first-child div div{
width: 10px; /*定义黑色瞳孔的大小*/
height: 10px;
background: #ffffff;
border-radius: 50%;
position: absolute; /*定义黑色瞳孔的位置,相对于眼珠的位置*/
top: 7px;
left: 10px;
}
/*右眼珠和左眼珠画法一样*/
.face>div:last-child div{
width: 20px;
height: 25px;
background: #000;
border-radius: 50%;
position: absolute;
top: 45px;
}
/*右瞳孔和左瞳孔的画法一样*/
.face>div:last-child div div{
width: 10px;
height: 10px;
background: #ffffff;
border-radius: 50%;
position: absolute;
top: 7px;
}
.nose{
width: 30px; /*定义红鼻子的大小*/
height: 30px;
border-radius: 50%;
background: #c70000;
position: absolute;
top: 130px;
left: 50%;
margin-left: -15px;
z-index: 10;
}
.nose div{
width: 10px; /*定义红鼻子里面白色圈圈的大小*/
height: 10px;
border-radius: 50%;
position: absolute;
background: #ffffff;
top: 10px;
margin-left: 20px;
z-index: 10;
}
.nose1{
width: 2px; /*定义红鼻子下面的那一条黑线*/
height: 130px;
background: #000;
position: absolute;
top: 160px;
left: 50%;
margin-left: -1px;
z-index: 10;
}
哆啦a梦的头部.png
画哆啦a梦的嘴巴部分
- 嘴巴应该是很简单的了吧,看一眼就知道是是用边框+border-radius实现的。
<div class="mouth"></div>
.mouth{
width: 250px; /*定义嘴巴的大小*/
height: 200px;
border-radius: 50%;
background: snow;
border-bottom: 2px #000 solid;
margin: -230px auto;
position: relative; /*定义嘴巴的位置*/
}
哆啦a梦的嘴巴.png
画哆啦a梦的胡须部分
胡须部分其实在上一篇文章画html打造动画【连载3】- 小猫笑脸动画里面画胡须的时候就已经介绍了画胡须的方法,在这里就不赘述了,基本思路都是一样的。
<!-- 胡须 -->
<div class="beard">
<!-- 左边胡须部分 -->
<div class="left">
<!-- 第一根胡须 -->
<div></div>
<!-- 第二根胡须 -->
<div></div>
<!-- 第三根胡须 -->
<div></div>
</div>
<div class="right">
<div></div>
<div></div>
<div></div>
</div>
<!-- 脖子部分的小白条部分 -->
<span></span>
</div>
/*胡须样式*/
.beard .left div:first-child{
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 10% 90% 10% 90% / 10% 90% 10% 90%;
position: absolute;
left: 50%;
top: 140px;
margin-left: -170px;
z-index: 100;
}
.beard .left div:nth-child(2){
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 10% 90% 10% 90% / 30% 70% 40% 60%;
position: absolute;
left: 50%;
top: 170px;
margin-left: -170px;
z-index: 100;
}
.beard .left div:last-child{
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 10% 90% 10% 90% / 40% 60% 10% 90%;
position: absolute;
left: 50%;
top: 200px;
margin-left: -170px;
z-index: 100;
} .beard .right div:first-child{
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 90% 10% 90% 10% / 90% 10% 90% 10%;
position: absolute;
left: 50%;
top: 140px;
margin-left: 50px;
z-index: 100;
}
.beard .right div:nth-child(2){
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 90% 10% 90% 10% / 70% 30% 60% 40%;
position: absolute;
left: 50%;
top: 170px;
margin-left: 50px;
z-index: 100;
}
.beard .right div:last-child{
width: 120px;
height: 40px;
border-top: 2px #000 solid;
border-radius: 90% 10% 90% 10% / 60% 40% 90% 10%;
position: absolute;
left: 50%;
top: 200px;
margin-left: 50px;
z-index: 100;
}
.beard span{
display: block;
width: 60px;
height: 3.5px;
background: #ffffff;
border-radius: 4px;
position: absolute;
top: 352px;
left: 50%;
margin-left: -105px;
}
哆啦a梦的胡须.png
画哆啦a梦的脖子部分(脖子部分包括铃铛)
- 脖子就是基本div变形之后的图形,多余的部分隐藏到头部下面就可以了。
- 铃铛部分是各个很简单的基本图形组成。
<!-- 脖 -->
<div class="neck">
<!-- 铃铛的圆形 -->
<div></div>
<!-- 铃铛的小圆角矩形 -->
<div></div>
<!-- 铃铛的小圆形 -->
<div></div>
<!-- 铃铛的小竖线 -->
<div></div>
</div>
.neck{
width: 330px;
height: 200px;
border-radius: 50% 50% 20% 20% / 50% 50% 50% 50%;
background: #e30000;
margin: 80px auto;
z-index: 100;
}
.neck div:first-child{
border: 2px #000 solid;
border-radius: 50%;
width: 40px;
height: 40px;
background: #ffdd2e;
position: absolute;
top: 350px;
left: 50%;
margin-left: -22px;
transition: all 1s;
}
.neck div:nth-child(2){
border: 2px #000 solid;
width: 44px;
height: 5px;
background: #ffdd2e;
position: absolute;
left: 50%;
margin-left: -24px;
top: 363px;
border-radius: 5px;
transition: all 1s;
}
.neck div:nth-child(3){
width: 8px;
height: 8px;
border: 2px #000 solid;
position: absolute;
background: #6c5844;
border-radius: 50%;
left: 50%;
margin-left: -6px;
top: 375px;
transition: all 1s;
}
.neck div:nth-child(4){
width: 2px;
height: 8px;
background: #000;
position: absolute;
left: 50%;
margin-left: -1px;
top: 385px;
transition: all 1s;
}
哆啦a梦的脖子.png
完成哆啦a梦的动态效果
- 动起来的哆啦a梦才比较萌对吧,那我们就让它动起来吧(transition属性)。
- 鼠标移动到眼睛部位左眼珠移动到左边。
- 鼠标移动到嘴巴部位,脸部表情变化。
- 鼠标移动到铃铛部分,铃铛变大。
/*眼睛动效*/
.head:hover .face>div:first-child div{
left: 0px;
transition: all 1s;
}
.head:hover .face>div:first-child div div{
left: 0px;
transition: all 1s;
}
/*嘴巴动效,嘴巴的dom容器下面要加了个空的div容器*/
.mouth div:first-child{
width: 82px;
height: 2px;
background: #000;
position: absolute;
z-index: 1000;
top: -25px;
left: 6px;
display: none;
}
.mouth div:nth-child(2){
width: 82px;
height: 2px;
background: #000;
position: absolute;
z-index: 1000;
top: -25px;
left: 90px;
display: none;
}
.mouth:hover{
border-radius: 0;
width: 180px;
height: 200px;
}
.mouth:hover div:first-child,.mouth:hover div:nth-child(2){
display: block;
}
/*铃铛动效*/
.neck:hover div:first-child{
width: 60px;
height: 60px;
left: 50%;
margin-left: -30px;
}
.neck:hover div:nth-child(2){
width: 66px;
height: 7.5px;
left: 50%;
margin-left: -33px;
}
.neck:hover div:nth-child(3){
width: 12px;
height: 12px;
left: 50%;
margin-left: -6px;
top: 385px;
}
.neck:hover div:nth-child(4){
width: 2px;
height: 12px;
left: 50%;
margin-left: 1px;
top: 400px;
}
哆啦a梦动图.gif学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入学习交流群
343599877,我们一起学前端!
html打造动画【系列4】哆啦A梦的更多相关文章
- 纯CSS制作加<div>制作动画版哆啦A梦
纯CSS代码加上<div>制作动画版哆啦A梦(机器猫) 哆啦A梦(机器猫)我们大家一定都很熟悉,今天给大家演示怎么用纯CSS代码,来做一个动画版的哆啦A梦. 效果图: ###下面代码同学可 ...
- div+css制作哆啦A梦
纯CSS代码加上 制作动画版哆啦A梦(机器猫) 哆啦A梦(机器猫)我们大家一定都很熟悉,今天给大家演示怎么用纯CSS.代码,来做一个动画版的哆啦A梦. 效果图: 下面代码同学可以查看一下,每个线条及椭 ...
- 哆啦A梦欺骗了你!浏览器CSS3测试遭质疑
首先,说明,此处只是告诫各位参与CSS3.0学习使用或者将要使用或者学习CSS3.0的朋友,不要完全信任网络资源,依靠网络资源,我们需要利用网络资源的方便和可取的部分,结合自己的理解,学好,理解好! ...
- 弱肉强食——《哆啦A梦:大雄的新恐龙》观后感
观看大雄的新恐龙不是在电影院观看的,由于时间的问题无法去电影院观看,是在家通过梦蓝字幕组翻译好的观看的,这个翻译好的视频已经由于版权原因没有发布了. 故事的开始与以往的情节十分相似:大雄因为不想被胖虎 ...
- javascript动画系列第一篇——模拟拖拽
× 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...
- [css]我要用css画幅画(七) - 哆啦A梦
接着之前的[css]我要用css画幅画(六),今天画的有所不同,画的是哆啦A梦,我们小时候对他的称呼其实是小叮当机器猫. (PS:这次我要做的事情,很多人已经做过,这并不是什么创新,我只是在学习并记录 ...
- 创建【哆啦A梦】风格字体
学习canvas,为作画.对于一个毫无逻辑思维的人简直遭罪啊~想象坐标坐标坐标啊- - 好啦言归正传,基于本月16号,在春熙路IFS展出120只哆啦a梦,以及canvas的作用,在此介绍一种PS的美化 ...
- 哆啦A梦 canvas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【原】iOSCoreAnimation动画系列教程(二):CAKeyFrameAnimation【包会】
在上一篇专题文章[原]iOSCoreAnimation动画系列教程(一):CABasicAnimation[包会]中我们学习了iOS核心动画CoreAnimation中CABasicAnimation ...
随机推荐
- leetcode-55-跳跃游戏
题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: ...
- 九省联考 2018 Day 1 复现
前言 今年省选还有 15 天.每天针对性刷题学知识点有点枯燥,想到真题还没刷,就对着 pdf 做了一遍. A. 一双木棋 去年省选得了 25,应该是 \(n=2,m=2\) 的贪心和 \(m=1\) ...
- [Xamarin.Android] 如何透過電子郵件部署Xamarin.Android App (转帖)
Android App在部署到實機的時候不像iOS的App限制你一定要使用向Apple申請的開發者憑證,在Apple不管是你要上架到Apple Store或者是企業內部署,你都必須向蘋果申請憑證. 而 ...
- springboot项目:登录 登录aop拦截 使用Redis与cookie 进行设置获取清除操作
登录.登出: 第一步:在pom文件中引入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...
- 更换bbr内核
1:首先yum update -y更新到最新CentOS 7.3 1611cat /etc/redhat-releaseCentOS Linux release 7.3.1611 (Core) 2: ...
- 找到MySQL配置文件默认路径
如果不知道当前使用的配置文件的路径,可以尝试下面的操作: # which mysqld /usr/local/mysql/bin/mysqld # /usr/local/mysql/bin/mysql ...
- oauth2.0的授权流程详解
授权模式 1)oauth2.0 提供了四种授权模式,开发者可以根据自己的业务情况自由选择. 授权码授权模式(Authorization Code Grant) 隐式授权模式(简化模式)(Implici ...
- jQuery事件之传递参数
一.jQuery绑定事件的三种方法 我们这里首先复习一下jQuery绑定事件的三种方法: target.click(function(){}); target.on("click" ...
- C#(winform)为button添加背景图片,并去掉各种边框
1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 Button.Image = "" ...
- [作业] Python入门基础---九九乘法表
1.while 循环 : x = 1 while x < 10: y = 1 while y <=x: print('%d*%d=%2d' % (y,x,x*y),end = '\t') ...