使用css3动画须要2步css
animation
属性及属性值。各浏览器私有属性在前,通用属性在最后。@keyframes
定义动画过程名称。各浏览器私有属性在前,通用属性在最后。animation定义动画的属性值。
@keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改成新的样式。html
div { -webkit-animation: myfirst 5s; /* Safari Chrome opera */ -ms-animation: myfirst 5s; /* ie */ -moz-animation: myfirst 5s; /* ff */ animation: myfirst 5s; } @-webkit-keyframes myfirst /* Safari Chrome opera */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-ms-keyframes myfirst /* ie */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-moz-keyframes myfirst /* ff */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @keyframes myfirst { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} }
功能css3
from
,to
等同于0%,100%属性web
各浏览器私有属性在前,通用属性在最后。 chrome
// css
div {浏览器
-webkit-transition: width 2s; /* safari chrome */ -moz-transition: width 2s; /* ff */ -o-transition: width 2s; /* opera */ transition: width 2s; width: 200px; height: 200px;
}
.w {css3动画
width: 300px;
}
// html
<div></div>
// js
$('div').on('click', function () {动画
$('div').addClass('w')
}).net
功能3d
属性
transition
与animation
的区别在于前者只作过渡效果,后者着重作动画效果。若实在分不清就把transition
记为过渡。过渡是直线型的,不能够拆线。animation
记为动画。动画是能够作不少拆线型的。
div { -ms-transform: rotate(30deg); /* ie */ -webkit-s-transform: rotate(30deg); /* safari chrome opera */ -moz-s-transform: rotate(30deg); /* ff */ transform: rotate(30deg); }
功能
属性
|transform-origin|变形时的原点位置|center center|x-axis y-axis z-axis; // top left right bottom x% xpx|
|transform-box|定义排版盒子|border-box|fill-box, view-box, inherit, initial, unset|
|transform-type|嵌套元素是怎样在三维空间中呈现的|flat 二维| preserve-3d 三维|
transform
是变换(若不理解变换就理解为变形)。translate
是移动。是transform的一种属性值。没有动画。transition
是过渡。有动画。
2018/02/12 by stone