HTML5+CSS3+JS学习笔记-13-CSS3过渡和CSS3动画
2017-01-06 21:52
856 查看
学习了CSS3过渡和CSS3动画2个类似的功能
截图:
CSS3过渡,旋转45度同时缩小3/4长宽
代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS3过渡</title>
<style type="text/css">
/*
为了添加某种效果可以从一种样式转变到另一个的时候,
无需使用Flash动画或JavaScript。用鼠标移过下面的元素:
要实现这一点,必须规定两项内容:
指定要添加效果的CSS属性
指定效果的持续时间。
*/
div {
width: 400px;
height: 400px;
margin: 100px auto;
background-color: green;
transition: width 2s linear 2S, height 2s ease-out 2S, transform 2s;
-webkit-transition: width 2s linear 2S, height 2s ease-out 2S, -webkit-transform 2s;
}
/* transition:简写属性,用于在一个属性中设置四个过渡属性
* 1.规定应用过渡的 CSS 属性的名称;
* 2.定义过渡效果花费的时间。默认是 0;
* 3.规定过渡效果的时间曲线。默认是 "ease",linear,ease-out;
* 4.规定过渡效果何时开始。默认是 0。*/
div:hover {
width: 300px;
height: 300px;
transform: rotateZ(45deg);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
CSS3动画,自动变换背景颜色
代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS3动画练习</title>
<style type="text/css">
/*@keyframes规则是创建动画。
* @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。*/
/*当动画为 25% 及 50% 时改变背景色,然后当动画 100% 完成时再次改变*/
@keyframes myfirst {
from {
/*background: red;*/
/*0% {
background: red;
}
25% {
background: yellow;
}
50% {
background: blue;
}
100% {
background: green;
}*/
0% {
background: red;
left: 0px;
top: 0px;
}
25% {
background: yellow;
left: 200px;
top: 0px;
}
50% {
background: blue;
left: 200px;
top: 200px;
}
75% {
background: green;
left: 0px;
top: 200px;
}
100% {
background: red;
left: 0px;
top: 0px;
}
}
to {
/*background: yellow;*/
/*0% {
background: red;
}
25% {
background: yellow;
}
50% {
background: blue;
}
100% {
background: green;
}*/
0% {
background: red;
left: 0px;
top: 0px;
}
25% {
background: yellow;
left: 200px;
top: 0px;
}
50% {
background: blue;
left: 200px;
top: 200px;
}
75% {
background: green;
left: 0px;
top: 200px;
}
100% {
background: red;
left: 0px;
top: 0px;
}
}
}
@-webkit-keyframes myfirst
/* Safari 与 Chrome */
{
from {
background: red;
}
to {
background: yellow;
}
}
/*
当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。
指定至少这两个CSS3的动画属性绑定向一个选择器:
规定动画的名称
规定动画的时长
* */
div {
width: 400px;
height: 400px;
margin: 100px auto;
background-color: green;
animation: myfirst 4s ease ;
/*把 "myfirst" 动画捆绑到 div 元素,时长:5 秒:*/
-webkit-animation: myfirst 4s ease;
/* Safari 与 Chrome */
animation-iteration-count:4;/*规定动画被播放的次数。默认是 1*/
}
</style>
</head>
<body>
<div></div>
</body>
</html>
截图:
CSS3过渡,旋转45度同时缩小3/4长宽
代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS3过渡</title>
<style type="text/css">
/*
为了添加某种效果可以从一种样式转变到另一个的时候,
无需使用Flash动画或JavaScript。用鼠标移过下面的元素:
要实现这一点,必须规定两项内容:
指定要添加效果的CSS属性
指定效果的持续时间。
*/
div {
width: 400px;
height: 400px;
margin: 100px auto;
background-color: green;
transition: width 2s linear 2S, height 2s ease-out 2S, transform 2s;
-webkit-transition: width 2s linear 2S, height 2s ease-out 2S, -webkit-transform 2s;
}
/* transition:简写属性,用于在一个属性中设置四个过渡属性
* 1.规定应用过渡的 CSS 属性的名称;
* 2.定义过渡效果花费的时间。默认是 0;
* 3.规定过渡效果的时间曲线。默认是 "ease",linear,ease-out;
* 4.规定过渡效果何时开始。默认是 0。*/
div:hover {
width: 300px;
height: 300px;
transform: rotateZ(45deg);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
CSS3动画,自动变换背景颜色
代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>CSS3动画练习</title>
<style type="text/css">
/*@keyframes规则是创建动画。
* @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。*/
/*当动画为 25% 及 50% 时改变背景色,然后当动画 100% 完成时再次改变*/
@keyframes myfirst {
from {
/*background: red;*/
/*0% {
background: red;
}
25% {
background: yellow;
}
50% {
background: blue;
}
100% {
background: green;
}*/
0% {
background: red;
left: 0px;
top: 0px;
}
25% {
background: yellow;
left: 200px;
top: 0px;
}
50% {
background: blue;
left: 200px;
top: 200px;
}
75% {
background: green;
left: 0px;
top: 200px;
}
100% {
background: red;
left: 0px;
top: 0px;
}
}
to {
/*background: yellow;*/
/*0% {
background: red;
}
25% {
background: yellow;
}
50% {
background: blue;
}
100% {
background: green;
}*/
0% {
background: red;
left: 0px;
top: 0px;
}
25% {
background: yellow;
left: 200px;
top: 0px;
}
50% {
background: blue;
left: 200px;
top: 200px;
}
75% {
background: green;
left: 0px;
top: 200px;
}
100% {
background: red;
left: 0px;
top: 0px;
}
}
}
@-webkit-keyframes myfirst
/* Safari 与 Chrome */
{
from {
background: red;
}
to {
background: yellow;
}
}
/*
当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。
指定至少这两个CSS3的动画属性绑定向一个选择器:
规定动画的名称
规定动画的时长
* */
div {
width: 400px;
height: 400px;
margin: 100px auto;
background-color: green;
animation: myfirst 4s ease ;
/*把 "myfirst" 动画捆绑到 div 元素,时长:5 秒:*/
-webkit-animation: myfirst 4s ease;
/* Safari 与 Chrome */
animation-iteration-count:4;/*规定动画被播放的次数。默认是 1*/
}
</style>
</head>
<body>
<div></div>
</body>
</html>
相关文章推荐
- HTML5+CSS3+JS学习笔记-13-CSS3之box-sizing
- HTML5+CSS3+JS学习笔记-13-CSS3多列
- HTML5+CSS3+JS学习笔记-7-JS调节背景色
- HTML5+CSS3+JS学习笔记-12-使用JS及函数来制作表格加上3D透视效果
- HTML5+CSS3+JS学习笔记-8-使用JS及函数来制作表格
- HTML5+CSS3+JS学习笔记-2
- HTML5+CSS3+JS学习笔记-1
- HTML5+CSS3+JS学习笔记-5
- HTML5+CSS3+JS学习笔记-11-CSS3之3D转换的用法
- HTML5+CSS3+JS学习笔记-9-制作iphone手机模型
- HTML5+CSS3+JS学习笔记-5
- html css学习笔记-过渡,动画
- HTML5+CSS3+JS学习笔记-10-CSS3之2D转换的用法
- HTML5+CSS3+JS学习笔记-6
- HTML5+CSS3+JS学习笔记-4
- 韩顺平_轻松搞定网页设计(html+css+javascript)_第24讲_js案例讲解_js自定义函数_学习笔记_源代码图解_PPT文档整理
- javascript学习笔记(一) (2007-12-20 11:14:19| 分类: jsp+html+js+Ajax)
- UIView动画(过渡效果)的学习笔记
- 韩顺平_轻松搞定网页设计(html+css+javascript)_第25讲_js系统函数_js函数调用方式_学习笔记_源代码图解_PPT文档整理
- UIView动画(过渡效果)的学习笔记