使用css制作心形图案并且添加动画心动效果

比较简单,就直接上代码了

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      html,
      .chest {
        width: 80px;
        height: 80px;
        cursor: pointer;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .text {
        position: absolute;
        bottom: -20px;
        color: #ffd3d3;
      }

      .heart {
        position: absolute;
        z-index: 2;
        background: linear-gradient(-90deg, #f50a45 0%, #d5093c 10%);
        animation: beat 0.7s ease infinite;
      }

      .heart.center {
        background: linear-gradient(-45deg, #b80734 0%, #d5093c 10%);
      }

      .heart.top {
        z-index: 3;
      }

      .side {
        width: 35.2px;
        height: 35.2px;
        border-radius: 50%;
        top: 16px;
      }

      .center {
        width: 33.6px;
        height: 33.6px;
        bottom: 16px;
        left: 23.2px;
      }

      .left {
        left: 9.92px;
      }
      .right {
        right: 9.92px;
      }

      @keyframes beat {
        0% {
          transform: scale(1) rotate(225deg);
          box-shadow: 0 0 10px #d5093c;
        }

        50% {
          transform: scale(1.1) rotate(225deg);
          box-shadow: 0 0 10px #d5093c;
        }

        100% {
          transform: scale(1) rotate(225deg);
          box-shadow: 0 0 10px #d5093c;
        }
      }
    </style>
  </head>
  <body>
    <div class="chest" οnclick="moveDiv()">
      <div class="heart left side top"></div>
      <div class="heart center"></div>
      <div class="heart right side"></div>
      <div class="text">关注我们</div>
    </div>
  </body>
</html>
<script>
  function moveDiv() {
    var widthNumber = randomNum(10, document.documentElement.clientWidth);
    var heightNumber = randomNum(
      10,
      document.documentElement.clientHeight - 200
    );
    // 获取 <div> 元素
    var movingDiv = document.querySelector(".chest");
    // 隐藏 <div> 元素
    movingDiv.style.display = "none";
    setTimeout(function () {
      // 更新 <div> 元素的样式
      movingDiv.style.display = "flex";
      movingDiv.style.position = "absolute";
      movingDiv.style.left = widthNumber + "px";
      movingDiv.style.top = heightNumber + "px";
    }, 200); // 模拟延时效果
  }

  //生成从minNum到maxNum的随机数
  function randomNum(minNum, maxNum) {
    switch (arguments.length) {
      case 1:
        return parseInt(Math.random() * minNum + 1, 10);
        break;
      case 2:
        return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
        break;
      default:
        return 0;
        break;
    }
  }
</script>

如若转载,请注明出处:开源字节 https://sourcebyte.vip/article/359.html

相关推荐
鸿蒙布道师9 分钟前
OpenAI为何觊觎Chrome?AI时代浏览器争夺战背后的深层逻辑
前端·人工智能·chrome·深度学习·opencv·自然语言处理·chatgpt
袈裟和尚14 分钟前
如何在安卓平板上下载安装Google Chrome【轻松安装】
前端·chrome·电脑
曹牧18 分钟前
HTML字符实体和转义字符串
前端·html
小希爸爸23 分钟前
2、中医基础入门和养生
前端·后端
局外人LZ27 分钟前
前端项目搭建集锦:vite、vue、react、antd、vant、ts、sass、eslint、prettier、浏览器扩展,开箱即用,附带项目搭建教程
前端·vue.js·react.js
G_GreenHand41 分钟前
Dhtmlx Gantt教程
前端
鹿九巫42 分钟前
【CSS】层叠,优先级与继承(四):层叠,优先级与继承的关系
前端·css
卓怡学长1 小时前
w304基于HTML5的民谣网站的设计与实现
java·前端·数据库·spring boot·spring·html5
宝拉不想努力了1 小时前
vue element使用el-table时,切换tab,table表格列项发生错位问题
前端·vue.js·elementui
YONG823_API1 小时前
深度探究获取淘宝商品数据的途径|API接口|批量自动化采集商品数据
java·前端·自动化