html打造动画【连载4】- 哆啦a梦

一只神奇的喵

我相信每个人的童年都有一个哆啦a梦,一个小小的肚皮里装满了不可思议的哆啦a梦,一个在你无助伤心的时候陪在你身边的哆啦a梦,一个陪你胡思乱想陪你吃铜锣烧的哆啦a梦今天我们就来画一个我们心中的哆啦a梦吧

哆啦a梦.png

定义哆啦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梦的胡须部分
<!-- 胡须 -->
    <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

附上源码下载地址:http://www.html5tricks.com/download/css3-pretty-doraemon.rar

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容

  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,349评论 0 8
  • 附上7月4日晚8点的直播地址:https://www.mayigeek.com/mayi-edu-web/user...
    Iris_mao阅读 820评论 4 7
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,703评论 1 92
  • 惦念 挥手九年一念间,惦念思绪两行泪。 若问我心最惦念,唯有外公存心中。 因您宠我我惦您,同时外公是我最尊重的人。
    Brendamin阅读 140评论 0 0
  • 好久前收拾家当,翻出了高中的周记,回看那一个个小本子时忽然感觉以后的生活中缺少了些东西。那时为了凑每周周记的额定字...
    清水糊阅读 229评论 2 1