爱心代码-HTML

这篇具有很好参考价值的文章主要介绍了爱心代码-HTML。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

效果图:
代码生成的是动态的,跳动的心
可复制直接用
爱心代码html可复制,前端,html,前端,javascript文章来源地址https://www.toymoban.com/news/detail-742947.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>New Document</title>
    <meta name="Generator" content="EditPlus" />
    <meta name="Author" content="" />
    <meta name="Keywords" content="" />
    <meta name="Description" content="" />
    <style>
      html,
      body {
        height: 100%;
        padding: 0;
        margin: 0;
        background: #000;
      }
      canvas {
        position: absolute;
        width: 100%;
        height: 100%;
      }
      .a {
        width: 100px;
        height: 100px;
        position: absolute;
        left: 40%;
        top: 25%;
      }
      h3 {
        font-family: "fangsong";
        font-size: 6em;
        color: transparent;
      }
      span {
        display: table-cell;
        animation: san 3s linear infinite;
      }
      h3 span:nth-child(1) {
        animation-delay: 0s;
      }
      h3 span:nth-child(2) {
        animation-delay: 0.1s;
      }
      h3 span:nth-child(3) {
        animation-delay: 0.2s;
      }
      h3 span:nth-child(4) {
        animation-delay: 0.3s;
      }
      h3 span:nth-child(5) {
        animation-delay: 0.4s;
      }
      h3 span:nth-child(6) {
        animation-delay: 0.5s;
      }
      h3 span:nth-child(7) {
        animation-delay: 0.6s;
      }
      h3 span:nth-child(8) {
        animation-delay: 0.7s;
      }
      h3 span:nth-child(9) {
        animation-delay: 0.8s;
      }
      h3 span:nth-child(10) {
        animation-delay: 0.9s;
      }
      @keyframes san {
        0%,
        100% {
          color: rgb(255, 255, 255);
          text-shadow: 0 0 5px rgb(234, 128, 176), 0 0 15px rgb(234, 128, 176),
            0 0 25px rgb(234, 128, 176), 0 0 50px rgb(234, 128, 176),
            0 0 80px rgb(234, 128, 176), 0 0 120px rgb(234, 128, 176),
            0 0 160px rgb(234, 128, 176), 0 0 200px rgb(234, 128, 176),
            0 0 300px rgb(234, 128, 176), 0 0 400px rgb(234, 128, 176),
            0 0 500px rgb(234, 128, 176);
        }
        20%,
        80% {
          color: transparent;
          text-shadow: none;
        }
      }
    </style>
  </head>

  <body>
    <div class="a">
      <h3>
        <!-- <span>❤</span> -->
        <!-- <span>❤</span> -->
        <span></span>
      </h3>
    </div>
    <canvas id="pinkboard"></canvas>
    <script>
      /*
       * Settings
       */
      var settings = {
        particles: {
          length: 500, // maximum amount of particles
          duration: 2, // particle duration in sec
          velocity: 100, // particle velocity in pixels/sec
          effect: -0.75, // play with this for a nice effect
          size: 30, // particle size in pixels
        },
      };

      /*
       * RequestAnimationFrame polyfill by Erik Möller
       */
      (function () {
        var b = 0;
        var c = ["ms", "moz", "webkit", "o"];
        for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) {
          window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"];
          window.cancelAnimationFrame =
            window[c[a] + "CancelAnimationFrame"] ||
            window[c[a] + "CancelRequestAnimationFrame"];
        }
        if (!window.requestAnimationFrame) {
          window.requestAnimationFrame = function (h, e) {
            var d = new Date().getTime();
            var f = Math.max(0, 16 - (d - b));
            var g = window.setTimeout(function () {
              h(d + f);
            }, f);
            b = d + f;
            return g;
          };
        }
        if (!window.cancelAnimationFrame) {
          window.cancelAnimationFrame = function (d) {
            clearTimeout(d);
          };
        }
      })();

      /*
       * Point class
       */
      var Point = (function () {
        function Point(x, y) {
          this.x = typeof x !== "undefined" ? x : 0;
          this.y = typeof y !== "undefined" ? y : 0;
        }
        Point.prototype.clone = function () {
          return new Point(this.x, this.y);
        };
        Point.prototype.length = function (length) {
          if (typeof length == "undefined")
            return Math.sqrt(this.x * this.x + this.y * this.y);
          this.normalize();
          this.x *= length;
          this.y *= length;
          return this;
        };
        Point.prototype.normalize = function () {
          var length = this.length();
          this.x /= length;
          this.y /= length;
          return this;
        };
        return Point;
      })();
      /*
       * Particle class
       */
      var Particle = (function () {
        function Particle() {
          this.position = new Point();
          this.velocity = new Point();
          this.acceleration = new Point();
          this.age = 0;
        }
        Particle.prototype.initialize = function (x, y, dx, dy) {
          this.position.x = x;
          this.position.y = y;
          this.velocity.x = dx;
          this.velocity.y = dy;
          this.acceleration.x = dx * settings.particles.effect;
          this.acceleration.y = dy * settings.particles.effect;
          this.age = 0;
        };
        Particle.prototype.update = function (deltaTime) {
          this.position.x += this.velocity.x * deltaTime;
          this.position.y += this.velocity.y * deltaTime;
          this.velocity.x += this.acceleration.x * deltaTime;
          this.velocity.y += this.acceleration.y * deltaTime;
          this.age += deltaTime;
        };
        Particle.prototype.draw = function (context, image) {
          function ease(t) {
            return --t * t * t + 1;
          }
          var size = image.width * ease(this.age / settings.particles.duration);
          context.globalAlpha = 1 - this.age / settings.particles.duration;
          context.drawImage(
            image,
            this.position.x - size / 2,
            this.position.y - size / 2,
            size,
            size
          );
        };
        return Particle;
      })();

      /*
       * ParticlePool class
       */
      var ParticlePool = (function () {
        var particles,
          firstActive = 0,
          firstFree = 0,
          duration = settings.particles.duration;

        function ParticlePool(length) {
          // create and populate particle pool
          particles = new Array(length);
          for (var i = 0; i < particles.length; i++)
            particles[i] = new Particle();
        }
        ParticlePool.prototype.add = function (x, y, dx, dy) {
          particles[firstFree].initialize(x, y, dx, dy);

          // handle circular queue
          firstFree++;
          if (firstFree == particles.length) firstFree = 0;
          if (firstActive == firstFree) firstActive++;
          if (firstActive == particles.length) firstActive = 0;
        };
        ParticlePool.prototype.update = function (deltaTime) {
          var i;

          // update active particles
          if (firstActive < firstFree) {
            for (i = firstActive; i < firstFree; i++)
              particles[i].update(deltaTime);
          }
          if (firstFree < firstActive) {
            for (i = firstActive; i < particles.length; i++)
              particles[i].update(deltaTime);
            for (i = 0; i < firstFree; i++) particles[i].update(deltaTime);
          }

          // remove inactive particles
          while (
            particles[firstActive].age >= duration &&
            firstActive != firstFree
          ) {
            firstActive++;
            if (firstActive == particles.length) firstActive = 0;
          }
        };
        ParticlePool.prototype.draw = function (context, image) {
          // draw active particles
          if (firstActive < firstFree) {
            for (i = firstActive; i < firstFree; i++)
              particles[i].draw(context, image);
          }
          if (firstFree < firstActive) {
            for (i = firstActive; i < particles.length; i++)
              particles[i].draw(context, image);
            for (i = 0; i < firstFree; i++) particles[i].draw(context, image);
          }
        };
        return ParticlePool;
      })();

      /*
       * Putting it all together
       */
      (function (canvas) {
        var context = canvas.getContext("2d"),
          particles = new ParticlePool(settings.particles.length),
          particleRate =
            settings.particles.length / settings.particles.duration, // particles/sec
          time;

        // get point on heart with -PI <= t <= PI
        function pointOnHeart(t) {
          return new Point(
            160 * Math.pow(Math.sin(t), 3),
            130 * Math.cos(t) -
              50 * Math.cos(2 * t) -
              20 * Math.cos(3 * t) -
              10 * Math.cos(4 * t) +
              25
          );
        }

        // creating the particle image using a dummy canvas
        var image = (function () {
          var canvas = document.createElement("canvas"),
            context = canvas.getContext("2d");
          canvas.width = settings.particles.size;
          canvas.height = settings.particles.size;
          // helper function to create the path
          function to(t) {
            var point = pointOnHeart(t);
            point.x =
              settings.particles.size / 2 +
              (point.x * settings.particles.size) / 350;
            point.y =
              settings.particles.size / 2 -
              (point.y * settings.particles.size) / 350;
            return point;
          }
          // create the path
          context.beginPath();
          var t = -Math.PI;
          var point = to(t);
          context.moveTo(point.x, point.y);
          while (t < Math.PI) {
            t += 0.01; // baby steps!
            point = to(t);
            context.lineTo(point.x, point.y);
          }
          context.closePath();
          // create the fill
          context.fillStyle = "#ea80b0";
          context.fill();
          // create the image
          var image = new Image();
          image.src = canvas.toDataURL();
          return image;
        })();

        // render that thing!
        function render() {
          // next animation frame
          requestAnimationFrame(render);

          // update time
          var newTime = new Date().getTime() / 1000,
            deltaTime = newTime - (time || newTime);
          time = newTime;

          // clear canvas
          context.clearRect(0, 0, canvas.width, canvas.height);

          // create new particles
          var amount = particleRate * deltaTime;
          for (var i = 0; i < amount; i++) {
            var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
            var dir = pos.clone().length(settings.particles.velocity);
            particles.add(
              canvas.width / 2 + pos.x,
              canvas.height / 2 - pos.y,
              dir.x,
              -dir.y
            );
          }

          // update and draw particles
          particles.update(deltaTime);
          particles.draw(context, image);
        }

        // handle (re-)sizing of the canvas
        function onResize() {
          canvas.width = canvas.clientWidth;
          canvas.height = canvas.clientHeight;
        }
        window.onresize = onResize;

        // delay rendering bootstrap
        setTimeout(function () {
          onResize();
          render();
        }, 10);
      })(document.getElementById("pinkboard"));
    </script>
  </body>
</html>

到了这里,关于爱心代码-HTML的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • python编程游戏代码可复制,python编程游戏代码教程

    大家好,小编来为大家解答以下问题,python编程游戏代码大全,编程猫,python编程游戏代码大全200行,今天让我们一起来看看吧! Source code download: 本文相关源码 大家好,给大家分享一下python编程游戏代码大全,很多人还不知道这一点。下面详细解释一下python自动化运维应用。

    2024年04月10日
    浏览(39)
  • python游戏代码大全可复制,python最简单游戏代码

    大家好,小编来为大家解答以下问题,python游戏编程入门游戏代码,python游戏代码大全可复制,现在让我们一起来看看吧! 哈喽铁子们 表弟最近在学Python,总是跟我抱怨很枯燥无味,其实,他有没有认真想过,可能是自己学习姿势不对? 比方说,可以通过打游戏来学编程!

    2024年04月17日
    浏览(33)
  • python烟花代码简单可复制,python烟花代码怎么运行

    大家好,小编来为大家解答以下问题,Python烟花代码总体功能介绍,python烟花代码简单可复制,今天让我们一起来看看吧! 天是2023 的第9天,到了这个时间点,部分小伙伴已经开始复盘这一年的得与失。比如今年增加了多少技能点,看了多少本书,写了多少篇文章或者年前

    2024年01月22日
    浏览(39)
  • python游戏代码大全可复制,python小游戏代码大全

    大家好,本文将围绕python游戏编程入门游戏代码展开说明,python游戏代码大全可复制是一个很多人都想弄明白的事情,想搞清楚python小游戏代码大全需要先了解以下几个事情。 本篇文章给大家谈谈如何用python编写一个简单的小游戏,以及如何用Python做小游戏让别人玩,希望对

    2024年04月08日
    浏览(41)
  • python游戏代码大全可复制,python简单的小游戏代码

    本篇文章给大家谈谈python游戏编程入门游戏代码,以及python游戏代码大全可复制,希望对各位有所帮助,不要忘了收藏本站喔。 大家好,小编来为大家解答以下问题,初学者怎么用python写简单小游戏教程,如何用python编写一个简单的小游戏,今天让我们一起来看看吧! 1、

    2024年03月20日
    浏览(44)
  • python游戏代码大全可复制,python超简单小游戏代码

    大家好,小编来为大家解答以下问题,python游戏编程入门游戏代码,python游戏代码大全可复制,现在让我们一起来看看吧! 大家好,小编为大家解答简单的python小游戏代码的问题。很多人还不知道python简单的小游戏代码,现在让我们一起来看看吧! 大家好,我是小F~ 经常听

    2024年02月19日
    浏览(39)
  • 数据结构:队列的链表结构(含完整代码,可复制)

    1.输出队列 2.入队一个元素 3.出队一个元素 5.建立链表队列 6.完整代码

    2024年01月16日
    浏览(35)
  • python做小游戏代码可复制,python编写小游戏的代码

    这篇文章主要介绍了python简单小游戏代码教程,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。 哈喽铁子们 表弟最近在学Python,总是跟我抱怨很枯燥无味,其实,他有没有认真想过,可能是自己学习姿

    2024年01月16日
    浏览(54)
  • python做小游戏代码可复制,python做小游戏代码300行

    本篇文章给大家谈谈用python做一个小游戏代码,以及python简单小游戏代码200行,希望对各位有所帮助,不要忘了收藏本站喔。 哈喽铁子们 表弟最近在学Python,总是跟我抱怨很枯燥无味,其实,他有没有认真想过,可能是自己学习姿势不对? 比方说,可以通过打游戏来学编程

    2024年03月14日
    浏览(37)
  • 完全可复制、经过验证的 Go 工具链

    原文在这里。 由 Russ Cox 发布于 2023年8月28日 开源软件的一个关键优势是任何人都可以阅读源代码并检查其功能。然而,大多数软件,甚至是开源软件,都以编译后的二进制形式下载,这种形式更难以检查。如果攻击者想对开源项目进行供应链攻击,最不可见的方式是替换正

    2024年02月10日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包