过渡与动画
一、过渡transition(设置在初始状态下)
(两个效果之间渐进的动画)
将元素的某个属性从“一个值”在指定的时间内过渡到“另一个值”
*属性名 持续时间 过渡方法
1.transition-property 属性名|all 对哪个属性进行变化(谓词属性)
多个属性过渡可以用all关键字
2.transition-duration 持续时间
3.transition-timing-function 过渡使用的方法(函数)
4.transition-delay (即时启动还是延时启动)
代码示例如下:
<div>web design</div>
div {
height: 30px;
width: 100px;
line-height: 30px;
border-radius:5px;
color:#000;
background-color:silver;
transition:all 1s linear;
}
div:hover {
color:white;
background-color:#45B823;
}
二、动画animation
1.定义动画@keyframes规则
2.调用动画animation属性
代码示例如下:
div:hover
{
animation: mycolor 5s linear;
}
@keyframes mycolor
{
0% {background-color:red;}
30% {background-color:blue;}
60% {background-color:yellow;}
100% {background-color:green;}
}
3D变换
一、3D transform-style: preserve-3d
坐标系:x轴rotateX() y轴rotateY() z轴rotateZ()
1.父容器: 旋转
transform-style: preserve-3d;
transform:rotateY(60deg);
舞台: 透视关系
眼睛到舞台的距离
perspective:100px;
二、旋转 transform属性
rotateX( )
rotateY( )
rotateZ( )
角度deg
三、透视 perspective属性
例子如下:
<div id="stage">
<div class="box x">
<img src="frog.jpg" />
</div>
<div class="box y">
<img src="frog.jpg" />
</div>
<div class="box z">
<img src="frog.jpg" />
</div>
</div>
#stage{
width: 300px;
margin: 100px auto;
perspective:100px;
}
.box{
width: 100px;
height:100px;
float:left;
transition:linear 1s;
transform-style: preserve-d;
}
img{
width:100px;
height:75px;
}
.x:hover
{
transform:rotateX(60deg);
}
.y:hover
{
transform:rotateY(60deg);
}
.z:hover
{
transform:rotateZ(60deg);
}