用css实现弧线动画

知识点:

  • @keyframes
  • perspective
  • animation
  • transform-origin
    以上详见mdn

看到的是别人的,自己写一遍是变成自己的开始

废话不多说,直接上代码

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>
    .card {
      width: 124.5px;
      height: 213px;
      position: fixed;
      left: calc(50% - 50px);
      top: calc(50% - 150px);
      transform: rotateX(45deg) rotateY(180deg) rotateZ(-90deg) translateY(300px);
      animation: rotate linear 3s forwards;
      transform-origin: center center -100px;
      cursor: pointer;
      background: url("./images/牌底.png") no-repeat 0 0 / cover;
    }
    
    @keyframes rotate {
      0% {
        transform: rotateX(45deg) rotateY(180deg) rotateZ(-90deg) translateY(400px) translateZ(-300px);
      }

      100% {
        transform: rotateX(45deg) rotateY(180deg) rotateZ(var(--rotateZ)) translateY(400px) translateZ(-300px);
      }
    }

    .container {
      width: 100vw;
      height: 100vh;
      position: fixed;
      perspective: 1000px;
    }
  </style>

</head>

<body>
  <script>
    const cards = []
    let i = 0;
    let prevTime = 0;
    const container = document.createElement("div")
    container.classList.add("container")

    for (let i = 0; i < 100; i++) {
      const card = document.createElement("div")
      card.classList.add("card")
      card.style.setProperty("--rotateZ", i * 1.8 - 90 + "deg")
      container.appendChild(card)
    }
    document.body.appendChild(container)
  </script>
</body>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值