使用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

相关推荐
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ew452182 小时前
ElementUI表格表头自定义添加checkbox,点击选中样式不生效
前端·javascript·elementui
suibian52352 小时前
AI时代:前端开发的职业发展路径拓宽
前端·人工智能
Moon.92 小时前
el-table的hasChildren不生效?子级没数据还显示箭头号?树形数据无法展开和收缩
前端·vue.js·html
垚垚 Securify 前沿站2 小时前
深入了解 AppScan 工具的使用:筑牢 Web 应用安全防线
运维·前端·网络·安全·web安全·系统安全
工业甲酰苯胺5 小时前
Vue3 基础概念与环境搭建
前端·javascript·vue.js
mosquito_lover16 小时前
怎么把pyqt界面做的像web一样漂亮
前端·python·pyqt
柴柴的小记9 小时前
前端vue引入特殊字体不生效
前端·javascript·vue.js
柠檬豆腐脑9 小时前
从前端到全栈:新闻管理系统及多个应用端展示
前端·全栈
bin91539 小时前
DeepSeek 助力 Vue 开发:打造丝滑的颜色选择器(Color Picker)
前端·javascript·vue.js·ecmascript·deepseek