课程概述

作业提交截止时间:09-01

任务目的

  • 深度理解掌握 transition-timing-function 以及它的意义
  • 学会配合使用 CSS transform 和CSS transition 制作流畅动画
  • 使用 CSS 伪元素触发过渡效果
  • 合理的使用 CSS 布局

任务描述

  • 在我们提供给你的 HTML 文件基础上,适当的添加 CSS transition 和 CSS transform 属性 ,实现视频 demo 中的效果;
  • 鼠标 hover 上去的时候,出现小猫笑起来的动画;
    动画 demo
    下载.html 文件
  • transition 和transform 各项子属性的值可以自定 ;
  • 对 CSS 布局比较感兴趣的同学,在学有余力的情况下,可以尝试自己用 CSS 画出小猫。

任务注意事项

  • 注意浏览器中的兼容性
  • 请注意代码风格的整齐、优雅
  • HTML 及 CSS 代码结构清晰、规范
  • 代码中含有必要的注释

在线学习参考资料


我的代码
<!DOCTYPE html>
<!-- saved from url=(0055)http://jadyoap.bj.bcebos.com/ife%2FcssCatAnimation.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>纯 CSS 实现猫笑起来的动画</title>
<style type="text/css">
body {
background-color: #d69a44;
}
/* face */
.face {
position: absolute;
left: 50%;
margin-left: -175px;
top:40px;
width: 350px;
height: 250px;
border-radius: 50% 50% 30% 30%;
border: 2px solid #3f200b;
z-index: 10;
background: #fbf8f1;
overflow: hidden;
}
/* ear */
.ear-wrap {
position: absolute;
width: 300px;
left: 50%;
margin-left: -150px;
/* top: 100px; */
}
.ear-wrap{
position: absolute;
left: 50%;
width: 300px;
margin-left: -150px;
margin-top: 20px;
}
.ear {
position: absolute;
width: 80px;
height: 100px;
border: 2px solid #000;
background: #fbf8f1;
border-radius: 100% 10% 50% 0% ;
transition: all 1s cubic-bezier(0.28, 0.50, 0.60, 0.83);
}
.ear-wrap .right {
left: auto;
right: 0;
border-radius: 10% 100% 0% 50%;
background: #f1ac2b;
}
/* 头发 */
.hair {
position: absolute;
width: 120px;
height: 120px;
left: 50%;
margin-left: 50px;
margin-top: -40px;
background: #f3b32e;
border-radius: 50% 50% 50% 50%;
}
/* 眼睛 */
.eye-wrap {
position: absolute;
width: 280px;
height: 70px;
top: 90px;
left: 50%;
margin-left: -140px;
overflow: hidden;
}
.eye {
height: 100px;
width: 100px;
position: absolute;
}
.eye-circle {
width: 100px;
height: 80px;
border: 2px solid #482507;
overflow: hidden;
position: absolute;
background: #fff;
border-radius: 50% 50% 40% 40%;
box-sizing: border-box;
}
.eye-core {
height: 55px;
width: 46px;
border-radius: 50% 50% 50% 50%;
/* margin: 0 auto; */
background: #000;
position: absolute;
left: 50%;
margin-left: -23px;
transition: all 1.2s cubic-bezier(0.51, 0.25, 0.41, 0.69);
}
.eye-bottom {
height: 50px;
width: 100px;
border-radius: 40% 40% 50% 50%;
position: absolute;
margin-top: 48px;
border-top: 2px solid #46240b;
background: #f6f7f2;
transition: all 1.2s;
}
.eye-wrap .right {
left: auto;
right: 0px;
}
.face-red {
position: absolute;
height: 20px;
width: 70px;
background: red;
top: 45px;
/*top: 64px;*/
left: 18px;
border-radius: 50% 50% 50% 50%;
background: #e85a5e;
opacity: 0.0;
transition: all 1.2s cubic-bezier(0.94, 0.26, 0.11, 0.58);
}
/* 鼻子 */
.nose {
width: 20px;
height: 10px;
border-bottom: 8px solid #000;
border-radius: 0% 0% 50% 50%;
top: 154px;
left: 50%;
margin-left: -10px;
position: absolute;
}
/* 嘴巴 */
.mouth-wrap {
position: absolute;
top: 168px;
width: 80px;
left: 50%;
margin-left: -40px;
height: 20px;
overflow: hidden;
}
.mouth {
width: 40px;
height: 40px;
border-bottom: 4px solid #000;
border-right: 4px solid #000;
border-radius: 0% 40% 50% 20%;
margin-top: -26px;
position: absolute;
left: 0;
transition: all 1.2s;
}
.mouth-wrap .right {
border-bottom: 4px solid #000;
border-right: none;
border-left: 4px solid #000;
border-radius: 40% 0% 20% 50%;
position: absolute;
left: auto;
right: 0;
}
/*鼠标hover样式 写在这里*/
.face:hover~.ear-wrap .left{
transform: rotate(-23deg);
transform-origin:50% 100%;
}
.face:hover~.ear-wrap .right{
transform: rotate(23deg);
transform-origin:50% 100%;
}
.face:hover .eye-core{
transform: scaleX(0.75);
}
.face:hover .eye-bottom{
transform: translateY(-15px);
}
.face:hover .face-red{
opacity: 1;
}
.face:hover .mouth{
border-radius: 0% 40% 50% 50%;
} </style>
</head><style type="text/css" id="4924523920"></style>
<body>
<div class="container">
<!-- 脸 -->
<div class="face">
<!-- 头发 -->
<div class="hair">
<div></div>
</div>
<!-- 眼睛 -->
<div class="eye-wrap">
<div class="eye left">
<div class="eye-circle">
<div class="eye-core"></div>
</div>
<div class="eye-bottom"></div>
<div class="face-red"></div>
</div>
<div class="eye right">
<div class="eye-circle">
<div class="eye-core"></div>
</div>
<div class="eye-bottom"></div>
<div class="face-red"></div>
</div>
</div>
<!-- 鼻子 -->
<div class="nose">
</div>
<!-- 嘴巴 -->
<div class="mouth-wrap">
<!-- <div class="mouth-top"></div> -->
<div class="mouth left"></div>
<div class="mouth right"></div>
</div>
</div>
<!-- 耳朵 -->
<div class="ear-wrap">
<div class="ear left"> </div>
<div class="ear right"> </div>
</div>
</div> </body></html>

总结一下:

①hover选择兄弟元素

            /*鼠标hover样式 写在这里*/
.face:hover{
cursor: pointer;
}
.face:hover~.ear-wrap .left{
transform :rotate(-30deg);
}
.face:hover~.ear-wrap .right{
transform :rotate(30deg);
}
.face:hover .face-red{
opacity: 0.8;
}

②利用transform,transition等完成猫笑的效果

No.3 - CSS transition 和 CSS transform 配合制作动画的更多相关文章

  1. css3-12 transition+css或transform实现过渡动画

    css3-12 transition+css或transform实现过渡动画 一.总结 一句话总结:首先要设置hover后的效果,然后在transition里面指定执行哪些样式和执行时间为多长. 1. ...

  2. Atitti css transition Animation differ区别

    Atitti  css   transition Animation differ区别 1.1. transition的优点在于简单易用,但是它有几个很大的局限.  1 1.2. Transition ...

  3. Atitti  css   transition Animation differ区别

    Atitti  css   transition Animation differ区别 1.1. transition的优点在于简单易用,但是它有几个很大的局限.  1 1.2. js 动态改变 st ...

  4. css transition 实现滑入滑出

    transition是css最简单的动画. 通常当一个div属性变化时,我们会立即看的变化,从旧样式到新样式是一瞬间的,嗖嗖嗖!!! 但是,如果我希望是慢慢的从一种状态,转变成另外一种状态,怎么办?  ...

  5. css中zoom和transform:scale的区别

    css中zoom和transform:scale的区别 关于zoom: 以前只是看到别人的代码中用过zoom,自己从未使用过,今天在探究ie7兼容inline-block时,发现里面提到了zoom.下 ...

  6. Css transition

    CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值. <!DOCTY ...

  7. CSS transition 的默认值

    语法 transition: property duration timing-function delay|initial|inherit; 示例: div {   width: 100px;    ...

  8. CSS transition & shorthand property order

    CSS transition & shorthand property order shorthand property https://developer.mozilla.org/en-US ...

  9. 奇妙的 CSS shapes(CSS图形) 【css 图形,绘图,CSS 几何图形)】

    http://www.cnblogs.com/coco1s/p/6992177.html <!DOCTYPE html> <html> <head> <met ...

随机推荐

  1. java中的奇葩 “:”

    一.经常使用java的人有没有发现java也可以将汉字作为标识符出现呢? 在Java语言中,标识符是以字母.下划线(_)或美元符($)开头,由字母.数字.下划线(_)或美元符($)组成的字符串 真的输 ...

  2. MySQL的预编译功能

      1.预编译的好处 大家平时都使用过JDBC中的PreparedStatement接口,它有预编译功能.什么是预编译功能呢?它有什么好处呢? 当客户发送一条SQL语句给服务器后,服务器总是需要校验S ...

  3. Hibernate 注解(Annotations 四)多对多双向注解

    注解(Annotation),也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它可以声明在包.类.字段.方法.局部变量.方法参数等的前面,用来 ...

  4. Bzoj3277:串

    题面 传送门 Sol 广义\(sam\) 每个\(sam\)的状态开\(set\)记录属于哪些串 \(parent\)树上启发式合并\(set\) 然后每个串就在上面走,通过不停地跳\(parent\ ...

  5. PDO drivers no value in Windows 或 ndefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY'

    把办公室的drupal7.54版本放到自己的笔记本(OS:Windows10 Pro,php:7.0.9,mysql 5.7.11,apache:2.4)上运行不了,查看了各项配置应该没问题啊.之前还 ...

  6. 为什么推荐用ui-router替代ngRoute

    初学angularjs,第一个实例是官网的phoneCat,里面路由用的是ngRoute,后来看到别的用ui-router,觉得好奇,ui-route是什么呢?百度一些,得到如下解释: ui-rout ...

  7. Codeforces Round #419 A+B

    A. Karen and Morning time limit per test  2 seconds memory limit per test  512 megabytes   Karen is ...

  8. zTree 学习笔记之(一)

    zTree 学习笔记之(一) 简介 zTree 是一个依靠 jQuery 实现的多功能 “树插件”.优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. 到底有哪些具体的优点,可以参见官网 ...

  9. Datatables跳转到指定页

    因为项目用到Datatables发现在分页特别多时无法跳转到指定页,自己动手增加了#Datatables 跳转到指定页#功能,实现代码如下: table = $('#user-table').data ...

  10. 对于大型公司项目平台选择j2ee的几层认识

    我是一个从野路子上一路走来的程序员,现在主要用.net做方案.选.net不选jave并没有什么特别的原因,只不过是因为我自己从c,java学起,后来被vs这个工具所吸引, 很熟悉这个平台罢了,从业15 ...