复习(css过渡与动画)

过渡属性

transition   

在这里插入图片描述
用于在一个属性中设置四个过渡属性。
代码:

div{
    width: 100px;
    height: 100px;
    background: red;
   transition: width 2s , height 2s
}
div:hover{
    width: 300px;
    height: 300px;

}

效果:

当鼠标移上去的时候这个正方形的宽度会增加 300 像素

transform

在这里插入图片描述
实现四个功能:旋转,倾斜,缩放,位移
代码:
div{
width: 100px;
height: 100px;
background: red;
transition: width 2s , height 2s ,transform 2s;
}
div:hover{
width: 300px;
height: 300px;
transform: rotate(180deg);
}

translate(x y)位移

rotate()旋转 transform:rotate(角度deg)负 右 正 左
skew()倾斜 transform:skewx(deg)或skewy(deg);;
scale()缩放 transform:scale(倍数); (大于1放大小于1缩小)

 transition-property   

规定应用过渡的 CSS 属性的名称。

transition-duration

定义过渡效果花费的时间。默认是 0。

代码:
div{
width: 100px;
height: 100px;
background: red;
transition-duration: 4s;
}
div:hover{
height: 300px;

}

transition-timing-function

规定过渡效果的时间曲线。默认是 “ease”。
在这里插入图片描述
代码:
div{
width: 100px;
height: 100px;
background: red;
transition-timing-function: linear;

}
div:hover{
height: 300px;

}
transition-delay

规定过渡效果何时开始。默认是 0。

div{
width: 100px;
height: 100px;
background: red;
transition-delay: 2s;

}
div:hover{
height: 300px;

}

css动画属性

@keyframes   

在这里插入图片描述
规定动画。

animation

在这里插入图片描述

代码:
div{
width:100px;
height:100px;
background:red;
animation:one 5s; 这句的意思:动画执行时间
}
@keyframes one
{
from{background: red;}
to{background: yellow;}

}
注意事项:
当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。

animation-duration

规定动画完成一个周期所花费的秒或毫秒。默认是 0。
代码:
div{
width:100px;
height:100px;
background:red;
animation: one;
animation-duration: 2s;
}

@keyframes one
{
0% {background:red;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}

}

animation-timing-function

规定动画的速度曲线。默认是 “ease”。
在这里插入图片描述
animation-delay

规定动画何时开始。默认是 0。
代码:
div{
width:100px;
height:100px;
background:red;
animation: one;
animation-duration: 2s;
animation-delay: 2s;
}

@keyframes one
{
0% {background:red;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}

}

animation-iteration-count

动画无限次播放:infinite

规定动画被播放的次数。默认是 1。
代码:
div{
width:100px;
height:100px;
background:red;
animation: one;
animation-duration: 2s;
animation-iteration-count: 3;
}

@keyframes one
{
0% {background:red;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}

}

animation-direction

动画正常播放 :normal
动画轮流反向播放: alternate

规定动画是否在下一周期逆向地播放。默认是 “normal”。

animation-play-state

暂停是 :paused
运行是 :running

规定动画是否正在运行或暂停。默认是 “running”。

代码:
div {
width:100px;
height:100px;
background:red;
position:relative;
animation:one;
animation-duration:5s;
animation-timing-function:linear;
animation-delay:1s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;

}

@keyframes one
{
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;}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值