创建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%;}</style></HEAD><BODY>
<canvas id="pinkboard"></canvas>
<script>/** Settings*/var settings = {particles: {length:   500, // maximum amount of particlesduration:   2, // particle duration in secvelocity: 100, // particle velocity in pixels/seceffect: -0.75, // play with this for a nice effectsize:      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 poolparticles = 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 queuefirstFree++;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 particlesif (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 particleswhile (particles[firstActive].age >= duration && firstActive != firstFree) {firstActive++;if (firstActive == particles.length) firstActive = 0;}};ParticlePool.prototype.draw = function(context, image) {// draw active particlesif (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/sectime;// get point on heart with -PI <= t <= PIfunction 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 canvasvar 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 pathfunction 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 pathcontext.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 fillcontext.fillStyle = '#ea80b0';context.fill();// create the imagevar image = new Image();image.src = canvas.toDataURL();return image;})();// render that thing!function render() {// next animation framerequestAnimationFrame(render);// update timevar newTime   = new Date().getTime() / 1000,deltaTime = newTime - (time || newTime);time = newTime;// clear canvascontext.clearRect(0, 0, canvas.width, canvas.height);// create new particlesvar 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 particlesparticles.update(deltaTime);particles.draw(context, image);}// handle (re-)sizing of the canvasfunction onResize() {canvas.width  = canvas.clientWidth;canvas.height = canvas.clientHeight;}window.onresize = onResize;// delay rendering bootstrapsetTimeout(function() {onResize();render();}, 10);})(document.getElementById('pinkboard'));
</script>
</BODY>
</HTML>

希望大家喜欢

HTML+CSS+JavaScript实现的动态爱心,超简单直接用!相关推荐

  1. HTML+CSS+JavaScript 实现登录注册页面(超炫酷)

    1.临近期末, 你还在为HTML网页设计结课作业,老师的作业要求感到头大?HTML网页作业无从下手? 网页要求的总数量太多? 2.没有合适的模板?等等一系列问题.你想要解决的问题,在这篇博文中基本都能 ...

  2. html 记住密码 自动登陆,JavaScript登录记住密码操作(超简单代码)

    废话不多说了,直接给大家贴代码了,具体代码如下所示: 记住密码 记住密码 window.onload = function(){ var oForm = document.getElementById ...

  3. html+css+javascript满屏雪花爱心520表白网站 (含音乐)520告白/七夕情人节/生日礼物/程序员表白必备

    ❉ html+css+javascript雪花爱心520表白网站 (含音乐)程序员表白必备 一年一度的/520情人节/七夕情人节/生日礼物/告白师妹/圣诞节/元旦节跨年/程序员表白, 程序员浪漫起来真 ...

  4. html+css+javascript满屏雪花爱心520表白网站 (含音乐)520告白/七夕情人节/生日礼物/程序员表白必备...

    ❉ html+css+javascript雪花爱心520表白网站 (含音乐)程序员表白必备 一年一度的/520情人节/七夕情人节/生日礼物/告白师妹/圣诞节/元旦节跨年/程序员表白, 程序员浪漫起来真 ...

  5. 七夕情人节~html+css+javascript实现满屏爱心特效(程序员表白)

    ❉ 七夕情人节 ❤html+css+j❤实现满屏爱心特效(程序员表白) ❤程序员表白, 很多人和小编一样受到暴击,需要告白的同学加紧了,不要错过这个好时机. ❤许多程序员小伙伴总是苦于找不到合适的告白 ...

  6. HTML5期末大作业:明星个人网站设计——权志龙(10页) 含设计报告HTML+CSS++JavaScript 个人网站模板下载 大学生简单DW个人网页作品代码 个人网页制作 学生个人网页

    HTML5期末大作业:明星个人网站设计--权志龙(10页) 含设计报告HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码 常见网页设 ...

  7. 基于HTML+CSS+JavaScript的个人动态网站设计

    全套资料下载地址:https://download.csdn.net/download/sheziqiong/85584271?spm=1001.2014.3001.5503 目录 1 主要内容 1 ...

  8. 学生个人网页设计作品:基于HTML+CSS+JavaScript实现摄影艺术网站 DIV布局简单的摄影主题网站

  9. HTML+CSS+JavaScript 制作电子版的烂漫爱心表白动画(程序员也是很烂漫的)

    HTML+CSS+JavaScript 制作电子版的烂漫爱心表白动画(程序员也是很烂漫的) 程序员给大家留下的印象往往是代码的机器,整天写代码-程序员不懂爱!其实这是对程序员一种片面的看法.程序员固然 ...

最新文章

  1. 3.产品成本在完工和在制产品间分配
  2. 读史记晋国世家0808:春秋平头哥
  3. 2019-12-06 数字信号处理的学科结构
  4. 隐马尔可夫模型的三个基本问题
  5. asp.net mvc4 mysql_ASP.NET MVC4 with MySQL: Configuration Error (MySql.Web.v20)
  6. 就在刚刚,人工智能微专业来啦
  7. C++Builder2010创建线程
  8. const 使用方法具体解释
  9. Android进阶学习-使用Canvas自定义ArcView(4)
  10. 常用的数据分析方法(聚类、因子、相关、对应、回归、方差)简述【转】
  11. 如何将卫星影像(高程)导出为西安80、北京54、国家2000坐标系
  12. 蓝牙技术|蓝牙音频LE Audio的技术特点
  13. SEO小白利用老域名将2个百度指数1000+的词快速上排名的案例
  14. 做开发十年,我总结出了这些开发经验
  15. 简单创意思维导图绘制教程分享
  16. python 语料_用python将语料转化为可计算的形式
  17. python 绘制玫瑰图
  18. 计算机显示u盘容量只有1m,为什么新买的U盘容量大小与实际显示大小不一样?...
  19. Java8 IF ELSE IF 优化
  20. 数据恢复软件:FonePaw Data Recovery for mac中文版

热门文章

  1. 分享11条PyCharm使用技巧,非常实用
  2. Newstar Ctf 2022| week2 wp
  3. uoj265【2016提高】愤怒的小鸟(状压dp)
  4. 苹果新系统耗电过快怎么解决(解决方法)
  5. 网路设备的端口镜像技术
  6. php获取x509证书信息,创建X509证书,并获取证书密钥的一点研究
  7. 理论:深入理解Linux文件系统与日志分析
  8. Ubuntu20.04 通过netplan 配置静态ip
  9. PHP中private、public、protected的区别详解
  10. 解决raw.githubusercontent.com地址DNS污染的方法参考