点赞效果 澎湃的心心,爱了 爱了

  html  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
   <label>
    <input type="checkbox">
    <svg viewBox="0 0 532 532">
        <path id="heart" transform="translate(10, 10)" d="M256,96.5l-19.7-20.3C186.1,24.3,104.5,15.9,49.7,62.6c-62.8,53.6-66.1,149.8-9.9,207.9l193.5,199.8 c12.5,12.9,32.8,12.9,45.3,0l193.5-199.8c56.3-58.1,53-154.3-9.8-207.9l0,0C407.5,15.9,326,24.3,275.7,76.2L256,96.5z"/>
      </svg>
      <span></span>
   </label>
</body>
</html>

css 

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
  }
  
  svg {
    width: 200px;
    position: relative;
    z-index: 10;
  }
  
  #heart {
    fill: #eee;
    stroke-width: 20px;
    stroke: red;
    stroke-dasharray: 1600;
    stroke-dashoffset: 1600;
    stroke-linecap: round;
  }
  
  span, span::after {
    display: block;
    width: 24px;
    height: 24px;
    background-color: transparent;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    
    box-shadow: 0 -160px 0 red, 0 160px 0 red, -160px 0 0 red, 160px 0 0 red;
  }
  
  span::after {
    content: '';
    transform: translate(-50%, -50%) rotate(45deg) scale(0);
  }
  
  input[type="checkbox"] {
    display: none;
  }
  
  label {
    cursor: pointer;
  }
  
  input[type="checkbox"]:checked + svg #heart {
    animation: 1s draw-heart linear forwards;
  }
  
  @keyframes draw-heart {
    0% {
      stroke-dashoffset: 1600;
    }
    80% {
      stroke-dashoffset: 0;
      fill: #eee;
    }
    100% {
      fill: red;
      stroke-dashoffset: 0;
    }
  }
  
  input[type="checkbox"]:checked ~ span {
    animation: .5s blink ease-in-out forwards .85s;
  }
  
  input[type="checkbox"]:checked ~ span::after {
    animation: .5s blink-after ease-in-out forwards .85s;
  }
  
  @keyframes blink {
    0% {
      transform: translate(-50%, -50%) scale(0.5);
      opacity: .8;
    }
    50% {
      transform: translate(-50%, -50%) scale(1);
      opacity: .8;
    }
    100% {
      transform: translate(-50%, -50%) scale(1.1);
      opacity: 0;
    }
  }
  
  @keyframes blink-after {
    0% {
      transform: translate(-50%, -50%) rotate(45deg) scale(0.5);
      opacity: .8;
    }
    50% {
      transform: translate(-50%, -50%) rotate(45deg) scale(1);
      opacity: .8;
    }
    100% {
      transform: translate(-50%, -50%) rotate(45deg) scale(1.1);
      opacity: 0;
    }
  }
  
  input[type="checkbox"]:checked + svg {
    animation: 1s pop linear forwards;
  }
  
  @keyframes pop {
    0% {
      transform: scale(1);
    }
    70% {
      transform: scale(1);
    }
    80% {
      transform: scale(1.2);
    }
    100% {
      transform: scale(1);
    }
  }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值