爱心html制作并部署github

news2024/10/6 20:35:06

手机也可以观看
效果预览地址

1.网页效果
在这里插入图片描述
心形优化
在这里插入图片描述

2.网页源码
源码地址

可以改变不同的图片,作者已经改为全局变量

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <script src="js/jquery-1.7.2.js"></script>
</head>
<style>
  * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  html,
  body {
    height: 100%;
    padding: 0;
    margin: 0;
    background: #000;
  }

  .tip {
    position: fixed;
    top: 10px;
    right: 10px;
    color: #fff;
    font-size: 20px;
  }

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

  .container {
    width: 100%;
    height: 100%;
  }

  /* .ranImg {
    position: fixed;
    display: none;
    width: 10%;
  } */

  canvas {
    z-index: 99;
    position: absolute;
    width: 100%;
    height: 100%;
  }
</style>

<body>
  <!-- tip -->
  <span class="tip">请点击一下</span>
  <!-- 樱花 -->
  <div id="jsi-cherry-container" class="container">
    <audio autoplay="autopaly" loop>
      <!-- 背景音乐 -->
      <source src="./Adagio.mp3" type="audio/mp3" />
      您的浏览器不支持播放声音
    </audio>
    <!-- 爱心 -->
    <canvas id="pinkboard" class="container"> </canvas>
  </div>

</body>

</html>
<script>

  let imgSrc1 = './caiwenji.jpg'
  let imgSrc2 = './lan.jpg'
  //音频
  document.addEventListener('click', musicPlay);
  function musicPlay() {
    document.querySelector('audio').play();
    document.removeEventListener('click', musicPlay);
    document.querySelector('.tip').style.display = 'none';
    randomImg();
  }

  //随机位置生成图片
  function randomImg() {
    setInterval(function () {
      createRanImg(imgSrc1);
      createRanImg(imgSrc1);
      createRanImg(imgSrc1);
    }, 1000)
    setInterval(function () {
      createRanImg(imgSrc2);
      createRanImg(imgSrc2);
      createRanImg(imgSrc2);
    }, 1200)
    setInterval(function () {
      createRanImg(imgSrc1);
      createRanImg(imgSrc1);
      createRanImg(imgSrc1);
    }, 1400)
    setInterval(function () {
      createRanImg(imgSrc2);
      createRanImg(imgSrc2);
      createRanImg(imgSrc2);
    }, 1600)
    setInterval(function () {
      //删除图片
      removeRanImg();
    }, 1500)
  }

  function createRanImg(imgSrc) {
    setTimeout(function () {
      let top = Math.round(Math.random() * (document.body.clientHeight - 200) + 100);
      let left = Math.round(Math.random() * (document.body.clientWidth - 200) + 100);
      let img = document.createElement('img');
      img.src = imgSrc;
      img.style.position = 'fixed';
      img.style.width = '10%';
      img.style.top = top + 'px';
      img.style.left = left + 'px';
      img.style.transition = 'all 0.5s';
      img.style.opacity = 0.3;
      let container = document.querySelector('#jsi-cherry-container');
      let pinkboard = document.querySelector('#pinkboard');
      container.insertBefore(img, pinkboard);
    }, 200)
  }

  function removeRanImg() {
    let container = document.querySelector('#jsi-cherry-container');
    let children = container.children;
    for (let i = 1; i < children.length - 1; i++) {
      container.removeChild(children[i]);
    }

  }



  /*
   * Settings
   */
  var settings = {
    particles: {
      length: 700, // maximum amount of particles         【最大颗粒量】
      duration: 2, // particle duration in sec            【力资持续时间(秒)】
      velocity: 300, // 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;
  })();

  /* 渲染canvas
   * 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)) / 1.4,
        (130 * Math.cos(t) -
          50 * Math.cos(2 * t) -
          20 * Math.cos(3 * t) -
          10 * Math.cos(4 * t) +
          25) / 1.4
      );
    }

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

3.上线github
(1)新建远程代码仓库
在这里插入图片描述
填写仓库名称
在这里插入图片描述

(2)推送代码到远程仓库

echo "# heart1" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/zhudunfeng/heart1.git
git push -u origin main

源文件命名要求:

必须index.html

在这里插入图片描述
(3)部署github pages
选择setting
在这里插入图片描述
选择pages
在这里插入图片描述选择/root点击save即可
在这里插入图片描述

心形代码参考:https://blog.csdn.net/Su_mer/article/details/127154474

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

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

相关文章

高并发,你真的理解透彻了吗?高并发核心编程手册荣登Github榜首

高并发&#xff0c;几乎是每个程序员都想拥有的经验。原因很简单&#xff1a;随着流量变大&#xff0c;会遇到各种各样的技术问题&#xff0c;比如接口响应超时、CPU load升高、GC频繁、死锁、大数据量存储等等&#xff0c;这些问题能推动我们在技术深度上不断精进。 在过往的面…

Spring Cloud Ablibaba 学习系列文章

前言&#xff1a; 最近发现Spring Cloud的应用越来越多了&#xff0c;微服务的概念在一般的互联网公司上面几乎都会使用到&#xff0c;于是准备一套Spring Cloud Alibaba的学习文章&#xff0c;文章写到一定阶段&#xff0c;会进行实战篇&#xff0c;比如搭建注册通信的框架&a…

C. Crossword Validation(字典树)

Problem - C - Codeforces 题意: 你得到了一个在NN网格上完成的填字游戏。每个单元格要么是填有字母的白色单元格&#xff0c;要么是黑色单元格。你还会得到一本包含M个不同单词的字典&#xff0c;其中每个单词都有一个与之相关的分数。网格中的一个横向候选词是在网格的同一行…

Android TCPIP常见问题

book: Understanding Linux Network Internals socket读写错误返回值&#xff1a;errno TCP: Robert Elliot Kahn IP: Robert Elliot Kahn, Vint Cerf 1 RFC规范 RFC793&#xff1a;TCP RFC768&#xff1a;UDP RFC791&#xff1a;IP RFC826&#xff1a;ARP RFC792&#xff1a;I…

请求转发与请求重定向的区别

目录 1.实现 2.具体区别 1.有关实现 请求转发与重定向分别对应forward 和 redirect两个关键字&#xff0c;接下来我们在Java中尝试去实现一下。 1.1 请求转发 我们一般使用两种方式实现&#xff0c;具体代码见下&#xff1a; RequestMapping("/fw")public Strin…

【C】语言文件操作(一)

&#x1f648;个人主页&#xff1a; 阿伟t &#x1f449;系列专栏&#xff1a;【C语言–大佬之路】 &#x1f388;今日心语&#xff1a;越忙&#xff0c;越要沉住气&#xff01; 本章重点 : 为什么使用文件什么是文件文件的打开和关闭文件的顺序读写文件的随机读写文本文件和…

Netty之I/O模型

UNIX提供的5种IO模型&#xff1a; 阻塞模型 阻塞IO模型&#xff1a; IO复用模型&#xff1a; 信号驱动IO模型&#xff1a; 对于五种IO模型我这里用自己的白话再复述一遍&#xff0c;加深理解&#xff0c;如果要看权威的解释可以自己去看《Netty权威指南》。 阻塞IO 进…

【算法】树状数组数据结构

文章目录Part.I 预备知识Chap.I 一些前提和概念Chap.II lowbit 函数Part.II 树状数组Chap.I 树状数组的思想Chap.II 树状数组的构造Part.III 树状数组的应用Chap.I LeetCode: 2426. 满足不等式的数对数目Sec.I 题目描述与分析Sec.II 代码实现Chap.II LeetCode: 51. 数组中的逆序…

计算机网络-网络层(ARP协议,DHCP协议,ICMP协议)

文章目录1. ARP协议2. DHCP协议3. ICMP协议1. ARP协议 首先数据在从网络层向下传递到数据链路层&#xff0c;在数据链路层中&#xff0c;要给报文封装源MAC地址和目的MAC地址。 其中获取目的MAC地址就是通过ARP协议 首先&#xff1a;每台主机都有一个ARP高速缓存&#xff08…

【VC++】字符串详解窗口第一个windows程序

注&#xff1a;最后有面试挑战&#xff0c;看看自己掌握了吗 文章目录系统调用顺序对比怎样避免确实动态链接库基本知识类型列表指针类型匈牙利标记法字符串详解Unicode 和 ANSI 函数TCHARs窗口WinMain我的博客即将同步至腾讯云开发者社区&#xff0c;邀请大家一同入驻&#xf…

微信小程序开发(超详细保姆式教程)

介绍&#xff1a; 微信里面app&#xff0c;16年推出 竞品&#xff1a;支付宝小程序&#xff0c;钉钉&#xff0c;美团&#xff0c;头条&#xff0c;抖音qq小程序 优点 1&#xff0c;在微信里面自由分享&#xff0c;2&#xff0c;不用下载app&#xff0c;3,能快速的开发&#xf…

【MySQL】如何把Windows上的MySQL数据库迁移到Linux服务器上

目录1. 前言2. 物理备份与逻辑备份3. mysqldump实现逻辑备份4. 逻辑恢复1. 前言 最近在学黑马的《瑞吉外卖》&#xff0c;前期的基础版本一致在 Windows 电脑上开发&#xff0c;包括 MySQL 数据库也是安装在 Windows 电脑上。最近才学到优化篇&#xff0c;安装了 Linux 虚拟机…

【成为红帽工程师】第二天 ssh远程连接服务器

目录 一、远程连接服务器 二、连接加密技术 三、ssh远程连接服务 四、sftp用法介绍 五、相关实验 一、远程连接服务器 &#xff08;一&#xff09;什么是远程连接服务器 远程连接服务器通过文字或图形接口方式来远程登录系统&#xff0c;让你在远程终端前登录linux主机…

2022年最新山东交安安全员模拟真题及答案

百分百题库提供交安安全员考试试题、交安安全员考试真题、交安安全员证考试题库等&#xff0c;提供在线做题刷题&#xff0c;在线模拟考试&#xff0c;助你考试轻松过关。 43.危险性较大工程专项施工方案需要论证的&#xff0c;应当由建设单位组织召开专家论证会。 答案&#…

计算机毕业设计SSM财务管理系统【附源码数据库】

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

计算机毕业设计SSM城市智能公交系统【附源码数据库】

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

MyBatis(4)---多表查询

多表查询: 一对一:一篇博客对应着一个作者 一对多:一个作者对应着多篇博客 ResultMap和ResultType的区别: 1)字段映射不同:resultType适用于数据库字段名和实体类的名字是相同的&#xff0c;但是假设实体类的名字叫做username&#xff0c;但是数据库的名字是name&#xff0c;这…

MyBatis(3)

我们在进行指定ID进行删除的时候还可以加上一个属性:表示要传递的参数的类型是啥 <delete id"Delete" parameterType"java.lang.Integer">delete from user where userID#{userID}</delete> 我们现在先实现一个场景----我们来进行查询一下User…

【毕业设计】大数据共享单车数据分析系统 - python

文章目录0 前言1 项目背景2 项目分析思维导图3 项目分析具体步骤3.1 读取数据3.2 数据分析3.1.1 数据预处理——每日使用量分析3.1.2 连续7天的单日使用分析结论3.1.3 数据预处理——每日不同时间段的使用量分析3.1.4 每日不同时间段使用量分析结论3.1.5 数据预处理——骑行距离…

【C++】智能指针

一、资源的管理 RAII:Resource Acquisition Is Initialization的简称&#xff0c;其翻译过来就是“资源获取即初始化”&#xff0c;即在构造函数中申请分配资源&#xff0c;在析构函数中释放资源&#xff0c;它是C语言中的一种管理资源、避免泄漏的良好方法。 C语言的机制保证…