CSS3动画属性总结

本文介绍了CSS中的关键帧动画,并通过一个具体的例子展示了如何创建一个背景颜色从绿色渐变到紫色,并且元素位置从左到右平移的动画。动画的属性包括名称、持续时间、延迟、运动曲线、方向、填充模式和迭代次数。此外,当鼠标悬停在元素上时,动画暂停,体现了交互性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <style>
    /*定义动画*/
    @keyframes move {
      from{
        background-color: #a5f5cd;
        transform: translate(0px);
      }
      to{
         background-color: #eab9d2;
        transform: translate(500px);
      }
    }


    /*盒子*/
    div{
        width: 100px;
        height: 100px;
        background-color: #ff0000;
        /*动画名*/
        animation-name: move;
        /*动画持续时间*/
        animation-duration: 2s;
        /*开始延迟时间*/
        animation-delay: .5s;
        /*动画运动轨迹 ease缓慢 linear匀速 */
        animation-timing-function: ease;
        /*运动的方向 reverse 反向 normal正常 alternate奇次正常,偶次反向 alternate-reverse 偶次正常,奇次反向*/
        animation-direction: alternate;
        /*保留动画格式 forwards保留最后一帧的格式 backwoards保留原格式 both 保留第一帧和最后一帧*/
        animation-fill-mode: both;
        /*动画执行的次数 infinte 无限次 */
        animation-iteration-count: infinite;

    }

    div:hover{
        /*动画状态  paused暂停  runing正常*/
      animation-play-state: paused;
    }

  </style>
</head>
<body>
  <div></div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值