情人节快乐
代码语言:html
所属分类:表白
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> /******************** Common ********************/ html, body { height: 100%; width: 100%; font-family: Helvetica, verdana, monospace; color: #FF0383; font-size: 100%; padding: 0; margin: 0; letter-spacing: 0.2rem; overflow: hidden; background: #ffdde1; } a { color: #FF0383; text-decoration: none; } h1 { font-size: 1.6rem; } h2 { padding: 0.8rem 0 0 0; } p { padding: 0.8rem 0; font-size: 0.8rem; } div#main { position: absolute; top: 0; left: 0; padding: 1.6rem; } p#loading { position: absolute; bottom: 0; right: 0; padding: 1.6rem; } /******************** Contents ********************/ canvas#canvas { background: #ffdde1; } </style> </head> <body> <div id="contents"> <canvas id="canvas">This browser cannot use a canvas.</canvas> </div> <script> (function () { 'use strict'; window.addEventListener('load', function () { var canvas = document.getElementById('canvas'); if (!canvas || !canvas.getContext) { return false; } /******************** Animation ********************/ window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (cb) { setTimeout(cb, 17); }; /******************** Random Number ********************/ function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } /******************** Var ********************/ // canvas var ctx = canvas.getContext('2d'); var X = canvas.width = window.innerWidth; var Y = canvas.height = window.innerHeight; var mouseX = X / 2; var mouseY = Y / 2; // heart var miniHeartNum = 100; var miniHearts = []; var rad = Math.PI / 180; var GRAVITY = 0.01; /******************** Text ********************/ var fontSize = '64px Arial'; if (X < 768) { fontSize = '24px Arial'; } function drawtext() { ctx.fillStyle = 'rgb(255, 3, 131)'; ctx.globalAlpha = 0.7; ctx.textBaseline = 'middle'; ctx.font = fontSize; ctx.textAlign = 'center'; ctx.fillText("Happy Valentine's Day", X / 2, Y / 2); } /******************** Particle ********************/ // var var particleNum = 50; var particles = []; var particleColors = ['rgb(0, 172, 176)', 'rgb(253, 191, 16)', 'rgb(237, 26, 36)', 'rgb(241, 87, 49)', 'rgb(246, 149, 153)']; function Particle(ctx, x, y, r) { this.ctx = ctx; this.init(x, y, r); } Particle.prototype.init = function (x, y, r) { this.x = x; this.y = y; this.r = r; this.l = rand(0, 5); this.a = 0.5; this.c = particleColors[rand(0, particleColors.length - 1)]; this.v = { x: rand(-2, 2) * Math.random(), y: rand(-2, 2) * Math.random() }; }; Particle.prototype.updateParams = function () { this.l -= 0.1; this.r += 0.1; }; Particle.prototype.updatePosition = function () { this.x += this.v.x; this.y += this.v.y; }; Particle.prototype.wrapPosition = function () { if (this.l < 0) { var miniHeart = new MiniHeart(ctx, this.x, this.y, this.r, this.c); miniHearts.push(miniHeart); this.x = mouseX; this.y = mouseY; this.l = rand(10, 20); this.r = 1; } }; Particle.prototype.draw = function () { ctx = this.ctx; ctx.save(); ctx.beginPath(); ctx.globalAlpha = this.a; ctx.fillStyle = this.c; ctx.arc(this.x, this.y, this.r, Math.PI * 2, false); ctx.fill(); ctx.closePath(); ctx.restore(); }; Particle.........完整代码请登录后点击上方下载按钮下载查看
网友评论0