模仿支付宝支付成功特效:svg圆圈转动+打钩

效果图(这里用点击事件来模拟触发事件):

在这里插入图片描述

代码:

HTML

    <main>
      <div class="box">
        <svg class="arrow" width="40" height="40" viewBox="0 0 40 40">
          <circle
            cx="50%"
            cy="50%"
            r="19"
            fill="none"
            stroke="#ffffff"
            stroke-width="2"
            class="circle"
          ></circle>
          <polyline
            points="8,20 18,30 30 12"
            fill="none"
            stroke="#ffffff"
            stroke-width="2"
            class="hookmark"
          ></polyline>
        </svg>
      </div>
    </main>

css

   <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      main {
        display: flex;
        align-items: center;
        justify-content: center;

        height: 100vh;
      }
      /* 按钮添加样式 */
      .box {
        width: 180px;
        height: 60px;
        background-image: linear-gradient(160deg, #0093e9, #80d0c7);
        border-radius: 8px;
        cursor: pointer;
        box-shadow: 0 2px rgba(0, 147, 233, 0.28);
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
      }
      /* 打钩样式 */
      .box .hookmark {
        opacity: 0;
      }
      /* 加载完成时 出现打钩的样式 */
      .box.completed .hookmark {
        opacity: 1;
        stroke-dasharray: 100 100;
        stroke-dashoffset: 100;
        animation: 1s linear hookmarkTransform forwards 0.5s;
      }

      /* 初始化圆圈(opacity: 0;隐藏状态) */
      .box .circle {
        opacity: 0;
        transition: all 2.5s;
        stroke-dasharray: 314;
        stroke-dashoffset: 314;
      }

      /* 加载完成时 圈圈出现 */
      .box.completed .circle {
        opacity: 1;
        stroke-dashoffset: 0;
      }

      /* 打钩的动态样式 */
      @keyframes hookmarkTransform {
        from {
          stroke-dasharray: 100 100;
          stroke-dashoffset: 100;
        }
        to {
          stroke-dasharray: 100 100;
          stroke-dashoffset: 0;
        }
      }
    </style>

JS

var uploadButton = document.querySelector('.box')

uploadButton.addEventListener('click', () => {
  // //点击事件
  uploadButton.classList.add('completed')
})

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值