HTML爱心网页制作[樱花+爱心]

news2025/3/1 1:27:55

HTML+CSS+JavaScript实现

先点赞后观看,养成好习惯
“不想动手的小伙伴可以直接拿网盘成品”
阿里云盘------提取码: 0d5j

效果图

1
注:任意浏览器都可以,建议使用谷歌浏览器

代码部分

代码如下仅供参考
可以直接拿去复制粘贴

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="js/jquery.min.js"></script>
  </head>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    html,
    body {
      height: 100%;
      padding: 0;
      margin: 0;
      background: #000;
    }

    .aa {
      position: fixed;
      left: 50%;
      bottom: 10px;
      color: #ccc;
    }

    .container {
      width: 100%;
      height: 100%;
    }
    canvas {
      z-index: 99;
      position: absolute;
      width: 100%;
      height: 100%;
    }
  </style>
  <body>
    <!-- 樱花 -->
    <div id="jsi-cherry-container" class="container">
      <audio autoplay="autopaly">
        <source src="renxi.mp3" type="audio/mp3" />
      </audio>
      <img class="img" src="./123.png" alt="" />
      <!-- 爱心 -->
      <canvas id="pinkboard" class="container"> </canvas>
    </div>

  </body>
</html>
<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
      },
    };

    (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>

  <script>
    var RENDERER = {
      INIT_CHERRY_BLOSSOM_COUNT: 30,
      MAX_ADDING_INTERVAL: 10,

      init: function () {
        this.setParameters();
        this.reconstructMethods();
        this.createCherries();
        this.render();
        if (
          navigator.userAgent.match(
            /(phone|pod|iPhone|iPod|ios|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
          )
        ) {
          // var box = document.querySelectorAll(".box")[0];
          // console.log(box, "移动端");
          // box.style.marginTop = "65%";
        }
      },
      setParameters: function () {
        this.$container = $("#jsi-cherry-container");
        this.width = this.$container.width();
        this.height = this.$container.height();
        this.context = $("<canvas />")
          .attr({ width: this.width, height: this.height })
          .appendTo(this.$container)
          .get(0)
        var rate = this.FOCUS_POSITION / (this.z + this.FOCUS_POSITION),
          x = this.renderer.width / 2 + this.x * rate,
          y = this.renderer.height / 2 - this.y * rate;
        return { rate: rate, x: x, y: y };
      },
      re
          }
        } else {
          this.phi += Math.PI / (axis.y == this.thresholdY ? 200 : 500);
          this.phi %= Math.PI;
        }
        if (this.y <= -this.renderer.height * this.SURFACE_RATE) {
          this.x += 2;
          this.y = -this.renderer.height * this.SURFACE_RATE;
        } else {
          this.x += this.vx;
          this.y += this.vy;
        }
        return (
          this.z > -this.FOCUS_POSITION &&
          this.z < this.FAR_LIMIT &&
          this.x < this.renderer.width * 1.5
        );
      },
    };
    $(function () {
      RENDERER.init();
    });
  </script>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/404981.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2022最新Web前端经典面试试题及答案-史上最全前端面试题(含答案)

程序员面试题库分享 1、前端面试题库 &#xff08;面试必备&#xff09; 推荐&#xff1a;★★★★★ 地址&#xff1a;前端面试题库 2、前端技术导航大全 推荐&#xff1a;★★★★★ 地址&#xff1a;前端技术导航大全 3、开发者颜色值转换工具 推荐&…

【vite·4】vite在多环境下的配置集成方案及defineConfig(非常详细)

vite的默认配置文件是vite.config.js&#xff0c;最基础的配置文件格式如下&#xff1a; export default {// 配置选项 };我们也可以通过 –config 命令行选项指定一个配置文件&#xff0c;命令行输入&#xff1a; vite --config my-config.js vite运行在node环境&#xff0c;…

【前端小技能】Vue集成百度离线地图

Vue项目集成百度离线地图 工作中遇到了一个需求&#xff0c;要在内网使用百度地图&#xff0c;那么肯定就是离线的地图了&#xff0c;查阅了一些博文&#xff0c;开发过程中也遇到了各种各样的问题&#xff0c;在此做下记录&#xff0c;希望带大家避坑&#xff0c;也给自己这两…

若依:如何去掉首页,设置登录后跳转到第一个路由菜单

若依系统是一个很好用的&#xff0c;开源的前端后台管理系统。 最近公司有一个需求&#xff0c;需要把默认的首页隐藏&#xff0c;登录后直接跳转到路由菜单返回的第一个页面。 查找了不少资料&#xff0c;但是都没有实际的解决方案。 不过最好自己还是实现了这个功能。 步骤…

Vue/React实现路由鉴权/导航守卫/路由拦截(react-router v6)

欢迎来到我的博客 &#x1f4d4;博主是一名大学在读本科生&#xff0c;主要学习方向是前端。 &#x1f36d;目前已经更新了【Vue】、【React–从基础到实战】、【TypeScript】等等系列专栏 &#x1f6e0;目前正在学习的是&#x1f525;React框架React框架React框架&#x1f525…

cnpm安装步骤

安装nodeJS 官网下载&#xff1a;http://nodejs.cn/download/ 选择其他版本下载地址:https://nodejs.org/zh-cn/download/releases/ 选版本点击下载 然后下载后缀名为msi,因为安装简单 选择好地址后无脑安装 二 、创建文件夹 安装完成后我们打开它的目录创建两个文件夹(…

从购买服务器到网站搭建成功保姆级教程~超详细

&#x1f60a;从购买服务器到网站搭建成功保姆级教程~真的超详细&#xff0c;各位看官细品&#x1f680;前言&#x1f680;预备知识&#x1f6a2;什么是云服务器&#xff1f;&#x1f6a2;什么是域名&#xff1f;&#x1f6a2;什么是SSL证书&#xff1f;&#x1f680;服务器选配…

防抖和节流(详细) 使用场景和区别

1.防抖 &#xff08;多次触发 只执行最后一次&#xff09; 作用&#xff1a; 高频率触发的事件,在指定的单位时间内&#xff0c;只响应最后一次&#xff0c;如果在指定的时间内再次触发&#xff0c;则重新计算时间 防抖类似于英雄联盟回城6秒&#xff0c;如果回城中被打断&…

微信小程序超详细知识点总结

一、微信小程序特点 二、使用准备 1.注册开发者帐号 2.下载微信开发者工具 3.微信开发文档 三、项目结构 四、配置文件 1、app.json pages 存放项目的页面 window 项目的窗口 tabBar 底部栏的配置 2、页面.json 五、小程序内置组件 逻辑视觉分区(div) 文本(span) …

微信小程序反编译简易教程与wxappUnpacker使用

文章目录前言一、工具准备1 解密工具2 逆向工具二、解密小程序1.确认小程序包位置2.打开一个小程序&#xff0c;3.解密小程序包三、逆向小程序1 安装依赖2 正式逆向3 其它人视频教程前言 方便微信小程序开发者&#xff0c;对前端思路的学习。所以必须学会小程序反编译技能。用…

【微信小程序】web-view 无法打开该页面不支持打开

本文相关文献&#xff1a; https://developers.weixin.qq.com/community/develop/doc/00084a350b426099ab46e0e1a50004?%2Fblogdetail%3Factionget_post_info 问题&#xff1a; 小程序开发时遇到了一个问题 我在正式上线版小程序使用 web-view 组件测试时提示&#xff1a;“无…

Vue2 跨域问题报错AxiosError net::ERR_FAILED、 Network Error、ERR_NETWORK

请求场景&#xff1a; 当前页面URL&#xff1a;http://127.0.0.1:8000/testcase 跳转请求页面URL&#xff1a;http://127.0.0.1:5000/testcase_orm 使用axios请求 时 页面提示跨域报错 跨域报错信息 Access to XMLHttpRequest at ‘http://127.0.0.1:5000/testcase_orm’ from…

前端面试题汇总(含答案)(JS篇)

主要自用&#xff0c;持续更新&#xff0c;相同类型的题目尽量放在了一起&#xff0c;参考的实在太多了就没有列出&#xff0c;侵权烦请联系删除。提示&#xff1a;自动生成的目录在页面右边---------->>>>>>>>>>>>>>>> Js的…

Node.js安装与配置(详细步骤)

前言 本篇博文记录了Node.js安装与环境变量配置的详细步骤&#xff0c;旨在为将来再次配置Node.js时提供指导方法。 另外&#xff1a;Node.js版本请根据自身系统选择&#xff0c;安装位置、全局模块存放位置和环境变量应根据自身实际情况进行更改。 Node.js安装与配置一、安装…

【独自开】--开发出属于自己的一套专属系统

文章目录前言独自开简介优秀案例独自开的使用平台福利及赚钱渠道平台福利赚钱渠道总结注册链接&#xff1a;前言 大家好&#xff0c;最近发现了一个宝藏开发平台&#xff0c;而且特别好用&#xff0c;今天就分享给大家&#xff1b; 这款开发平台名称为&#xff1a;《独自开》&a…

蓝桥冲刺31天之第八天

有人喜欢你&#xff0c;有人讨厌你&#xff1b; 有人在乎你&#xff0c;有人轻视你&#xff1b; 有人赞美你&#xff0c;有人批判你。 尊重所有的声音&#xff0c;但只成为自己&#xff1b; 不必借光而行&#xff0c;你我亦是星辰。 迷宫 只有一个题&#xff0c;迷宫&#x…

C. Celex Update(数学题)

C. Celex Update&#xff08;数学题&#xff09;一、问题二、分析三、代码一、问题 二、分析 这道题简单的来说就是在图上给定我们起点和终点&#xff0c;从起点到终点会有很多路径&#xff0c;不同的路径会经过不同的点&#xff0c;一条路径上经过的点可以计算出一个和&#…

第十一届——8走方格(找规律,规律总结)

题目&#xff1a;试题 H: 走方格时间限制: 1.0s 内存限制: 256.0MB 本题总分&#xff1a;20 分【问题描述】在平面上有一些二维的点阵。这些点的编号就像二维数组的编号一样&#xff0c;从上到下依次为第 1 至第 n 行&#xff0c;从左到右依次为第 1 至第 m 列&#xff0c;每一…

计算机科学导论笔记(八)

十、软件工程 软件工程是指合理利用工程方法和原则写出能在真实机器上工作的可靠软件的过程。 10.1 软件生命周期 软件生命周期是软件工程中的基础概念&#xff0c;软件和其他产品一样&#xff0c;周期性地重复着一些阶段。 软件开发完成之后&#xff0c;通常需要使用一段时…

【25】Verilog进阶 - 序列检测

VL25 输入序列连续的序列检测 本题并不难【中等】难度给高了 【做题关键】 (1)需要使用移位寄存器的思路。其实reg型是寄存器,也可以当做是移位寄存器,重要的是对其的处理,使用的是移位寄存器的思路 (2)注意新移入数据存放在低位 1 题目 + 代码 + TestBench 很简单,没…