css实战中,怎么绘制不断跳动的心形呢? 绘图的时候主要用到了transform: rotate(-45deg); transform-origin: 0 100%; transform: rotate(45deg); transform-origin: 100% 100%; 动画使用@keyframes 时间上为infinite。
效果图
源代码
/*
* @Author: 大剑师兰特(xiaozhuanlan),还是大剑师兰特(CSDN)
* @此源代码版权归大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
* @Email: 2909222303@qq.com
* @weixin: gis-dajianshi
* @First published in CSDN
* @First published time: 2023-11-12
*/
<template><div class="container"><div class="top"><h3>绘制不断跳动的心形</h3><div class="author">大剑师兰特, 还是大剑师兰特,gis-dajianshi</div></div><div class="heart"></div><div class="heart"></div><div class="heart"></div><div class="heart"></div><div class="heart"></div></div>
</template><style scoped>.container {width: 1000px;height: 580px;margin: 50px auto;border: 1px solid green;position: relative;}.top {margin: 0 auto 0px;padding: 10px 0;background: turquoise;color: #fff;}.heart {position: relative;width: 100px;height: 90px;margin: 90px 50px;float: left;}.heart::before,.heart::after {content: "";position: absolute;top: 40px;width: 52px;height: 80px;border-radius: 50px 50px 0 0;background: red;}.heart::before {left: 50px;transform: rotate(-45deg);transform-origin: 0 100%;}.heart::after {left: 0;transform: rotate(45deg);transform-origin: 100% 100%;}/* 定义动画 */@keyframes beat {0% {transform: scale(1);}50% {transform: scale(1.5);}100% {transform: scale(1);}}/* 应用动画 */.heart {animation: beat 1s infinite;}
</style>