纯HTML和CSS实现精美点赞效果

        纯HTML和CSS实现点赞效果,动态效果由CSS实现,主要有两个动画实现

        代码下面自取🖖

🎈效果如下

 HTML代码如下

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="like.css">
    <title>精美点赞效果</title>
</head>

<body>
    <label for="checkbox">
        <input type="checkbox" id="checkbox" hidden>
        <svg t="1651108144758" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
            p-id="3464" >
            <path
                d="M512 896a42.666667 42.666667 0 0 1-30.293333-12.373333l-331.52-331.946667a224.426667 224.426667 0 0 1 0-315.733333 223.573333 223.573333 0 0 1 315.733333 0L512 282.026667l46.08-46.08a223.573333 223.573333 0 0 1 315.733333 0 224.426667 224.426667 0 0 1 0 315.733333l-331.52 331.946667A42.666667 42.666667 0 0 1 512 896z"
                p-id="3465" id="heart"></path>
        </svg>
        <span class="dh"></span>
    </label>
</body>

</html>

like.css

*{
    margin: 0;
    padding: 0;
}

body{
    height: 100vh;
    display:flex;
    justify-content: center;
    align-items: center;
    /* 自定义属性 可通过var函数对齐调用*/
    --c:red;
}

svg{
    width: 200px;
    position: relative;
    z-index: 0;
}

#heart{
    fill:#eee;
    /* stroke 属性可应用于任何种类的线条,文字和元素,就像一个
    圆的轮廓 */
    stroke:var(--c);
    /* 线条宽度 */
    stroke-width: 40px;
    /* 设置线条为虚线,虚线的长度 */
    stroke-dasharray: 2600;
    /* 线条的位移 */
    stroke-dashoffset: 2600;
    /* 端点为圆头 */
    stroke-linecap: round;
}

span{
    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 var(--c),
    0 160px 0 var(--c),
    -160px 0 0 var(--c),
    160px 0 0 var(--c),
    -120px -120px 0 var(--c),
    120px -120px 0 var(--c),
    120px 120px 0 var(--c),
    -120px 120px 0 var(--c);
}

#checkbox:checked + svg #heart{
    animation: drawHeart 1s linear forwards;
}

#checkbox:checked ~ .dh{
    animation: blink 0.5 ease-in-out forwards;
    animation-delay: 0.85s;
}

label{
    cursor: pointer;
}

#checkbox:checked + svg{
    animation: beat 1s linear forwards;
}
@keyframes drawHeart{
    0%{
        stroke-dashoffset: 2600;
    }
    80%{
        fill:#eee;
        stroke-dashoffset: 0;
    }
    100%{
        fill: var(--c);
        stroke-dashoffset: 0;
    }
}

@keyframes blink {
    0%{
        transform: translate(-50%,-50%) scale(0.5);
        opacity: 0.8;
    }
    50%{
        transform: translate(-50%,-50%) scale(1);
        opacity: 1;
    }

    100%{
        transform: translate(-50%,-50%) scale(1.1);
        opacity: 0;
    }
}
/* 心跳动画 */
@keyframes beat{
    0%{
        transform: scale(1);
    }

    70%{
        transform: scale(1);
    }

    80%{
        transform: scale(1.2);
    }

    100%{
        transform: scale(1);
    }
}

项目中的心型图案可以在 IConfont中找

 

  • 7
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱躺平的威威

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值