页面飘落蒲公英动画

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的 CSS 动画花瓣飘落案例: HTML 代码: ``` <div class="petals-container"> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> <div class="petal"></div> </div> ``` CSS 代码: ``` .petal { width: 20px; height: 20px; border-radius: 50%; background-color: #ff8c94; position: absolute; top: -20px; animation: fall 4s linear infinite; } .petal:nth-child(1) { left: 10%; animation-delay: 0s; } .petal:nth-child(2) { left: 20%; animation-delay: 0.5s; } .petal:nth-child(3) { left: 30%; animation-delay: 1s; } .petal:nth-child(4) { left: 40%; animation-delay: 1.5s; } .petal:nth-child(5) { left: 50%; animation-delay: 2s; } .petal:nth-child(6) { left: 60%; animation-delay: 2.5s; } .petal:nth-child(7) { left: 70%; animation-delay: 3s; } .petal:nth-child(8) { left: 80%; animation-delay: 3.5s; } @keyframes fall { 0% { transform: translate(0, 0); } 100% { transform: translate(0, 800px); } } .petals-container { width: 100%; height: 800px; position: relative; overflow: hidden; } ``` 解释: 这个案例中,我们首先创建了一个包含 8 个 div 元素的容器。这些 div 元素就是花瓣。我们使用了 nth-child 选择器来为每个花瓣设置不同的左侧位置和动画延迟时间。 然后,我们为每个花瓣设置了一个名为“fall”的动画。该动画将花瓣从初始位置向下移动 800 像素。 最后,我们将容器设置为相对定位,并将其高度设置为 800 像素,以便在动画中显示所有花瓣。我们还将 overflow 属性设置为 hidden,以便隐藏容器外的任何溢出内容。 此时,你可以在浏览器中查看这个案例,并看到花瓣飘落的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值