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

相关推荐

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

    2024-07-20 05:00:03       17 阅读
  2. 给echarts图表添加弧形动画效果

    2024-07-20 05:00:03       24 阅读
  3. css 多种动画效果

    2024-07-20 05:00:03       58 阅读
  4. CSS动画效果

    2024-07-20 05:00:03       33 阅读
  5. WPF添加动画过渡效果

    2024-07-20 05:00:03       18 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 05:00:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 05:00:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 05:00:03       45 阅读
  4. Python语言-面向对象

    2024-07-20 05:00:03       55 阅读

热门阅读

  1. Spring Boot:简化Spring应用开发的利器

    2024-07-20 05:00:03       20 阅读
  2. JDBC常见用法

    2024-07-20 05:00:03       16 阅读
  3. 中介子方程六十二

    2024-07-20 05:00:03       17 阅读
  4. vue 中 ui 组件二次封装后 ref 怎么穿透到子组件里

    2024-07-20 05:00:03       16 阅读
  5. 求职学习day6

    2024-07-20 05:00:03       20 阅读
  6. AI Native应用中的模型微调

    2024-07-20 05:00:03       17 阅读
  7. c语言之 *指针与 **指针

    2024-07-20 05:00:03       16 阅读
  8. 【WPF开发】上位机开发-串口收发

    2024-07-20 05:00:03       18 阅读
  9. Eureka: 微服务架构中的服务发现与注册实践

    2024-07-20 05:00:03       18 阅读