CSS animation

动画避坑指南:

  1. 属性不要混用,如left :和 transform:translatex
  2. 举得例子中margin-left换成left就没法从平滑过渡到。需要为每一帧设置left。
  3. keyframes中如果100%没有设置,那么不是@keyframes中的0%作为100%,而是animation所在的样式为100%。
    animation-name:myanimation
    animation-duration:3s
    animation-timing-function:ease linear ease-in ease-out ease-in-out
    animation-delay:5s -2s
    animation-iteration-count:5 | infinite
    animation-direction:reverse alternate alternate-reverse normal
    animation-fill-mode:forwards backwards none both
<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 100px;
  height: 100px;
  background-color: green;
  animation-name: example;
  animation-duration: 10s;
  animation-iteration-count:4;
    position:relative;
}

@keyframes example {
  from {background-color: yellow;}
  80% {background-color: red;margin-left:500px;transform:rotate(45deg)}  

}
</style>
</head>
<body>

<p><b>注释:</b>本例在 Internet Explorer 9 以及更早的版本中无效。</p>

<div></div>

<p><b>注释:</b>当动画结束后,会变回最初的样式。</p>

</body>
</html>

8s的时间到红色
2s的时间回到绿色
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值