直接上效果

<!doctype html>
<html> <head>
<meta charset="utf-8">
<title>love++</title> <style>
html,
body { width: 500px;
height: 300px;
left: 50px;
top: 30px;
margin: 100px 289px; background: #f6d8e2;
} pp1 {
position: absolute;
top: 20px;
left: 20px;
} canvas {
position: absolute;
width: 1000px;
height: 500px;
left: 135px;
top: 50px;
}
</style>
<link href="css/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="d.js"></script> <script language="javascript" type="text/javascript"> // 18秒以后再跳转
setTimeout("javascript:location.href='./index.html'", 35000);
</script> </head> <div id="myContent"></div>
<div id="contentToWrite" class="comments"
style="margin-left: 39px;color: red;">大佬</div>
<div id="contentToWrite" class="comments"
style="margin-left: 39px;color:#f6d8e2;">00</div>
<div id="contentToWrite" class="comments"
style="margin-left: 30px;color: red;">我想你了</div>
<script type="text/javascript"> writeContent(true); </script>
</body> <body> <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(
180 * Math.pow(Math.sin(t), 3),
160 * 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 = '#fa759f';
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();
}, 50);
})(document.getElementById('pinkboard'));</script> </body>
<script>
var charIndex = -1;
var stringLength = 0;
var inputText; function writeContent(init) {
if (init) {
inputText = document.getElementById('contentToWrite').innerHTML;
}
if (charIndex == -1) {
charIndex = 0;
stringLength = inputText.length;
}
var initString = document.getElementById('myContent').innerHTML;
initString = initString.replace(/<SPAN.*$/gi, "");
var theChar = inputText.charAt(charIndex);
var nextFourChars = inputText.substr(charIndex, 4);
if (nextFourChars == '<BR>' || nextFourChars == '<br>') {
theChar = '<BR>';
charIndex += 3;
}
initString = initString + theChar + "<SPAN id='blink'>_</SPAN>";
document.getElementById('myContent').innerHTML = initString;
charIndex = charIndex / 1 + 1;
if (charIndex % 2 == 1) {
document.getElementById('blink').style.display = 'none';
} else {
document.getElementById('blink').style.display = 'inline';
}
if (charIndex <= stringLength) {
setTimeout('writeContent(false)', 300);
} else {
blinkSpan();
}
} var currentStyle = 'inline'; function blinkSpan() {
if (currentStyle == 'inline') {
currentStyle = 'none';
} else {
currentStyle = 'inline';
}
document.getElementById('blink').style.display = currentStyle;
setTimeout('blinkSpan()', 300);
}
</script> </html>

爱心代码_HTML的更多相关文章

  1. 纯css爱心代码-最近超级火的打火机与公主裙中的爱心代码(简易版)

    theme: cyanosis 最近打火机与公主裙中的爱心代码超级火,看着特别心动,让俺用css来写个简易版!!! 先看效果: 代码拆解: 主要是分为3大部分 分子颗粒 爱心 动画 代码实现: 分子颗 ...

  2. Python之——爱心代码参与情人节

    一行代码实现输出爱心图,参考https://zhuanlan.zhihu.com/p/23321351 原理: 1.借助数学函数——((x * 0.05) ** 2 + (y * 0.1) ** 2 ...

  3. 3d爱心代码

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 用CSS画基本图形

    用CSS画基本图形 1.正方形 代码如下: #square { width: 100px; height: 100px; background: red; } 2.长方形 代码如下:   #recta ...

  5. phpcms编辑器添加一键排版控件

    CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的 废话不多说,直接说步骤第一步:config.j ...

  6. 六行python代码的爱心曲线

    前些日子在做绩效体系的时候,遇到了一件囧事,居然忘记怎样在Excel上拟合正态分布了,尽管在第二天重新拾起了Excel中那几个常见的函数和图像的做法,还是十分的惭愧.实际上,当时有效偏颇了,忽略了问题 ...

  7. HTML5 Canvas爱心时钟代码

    这是一款数字时钟动画,数字又多个小爱心组成,又何问起整理,随着时间推进,每一秒钟新数字替换旧数字,旧数字离去使用天女散花动画,花是五颜六色的. 查看效果:http://hovertree.com/te ...

  8. javascript博客爱心特效代码与代码解析

    这个鼠标点击出现爱心的特效经常在别的博客里见到,于是我查了度娘后拿来直接用上了. 虽然不知道原作者是谁,但肯定是个大神,只有通过观摩他/她的代码膜拜一下啦. 直接上代码(解析在代码注释里): // 自 ...

  9. 程序员式优雅表白,教你用python代码画爱心

    还能用python代码画爱心?还有这种操作?这是什么原理? 不相信python代码可以画爱心?先来一张效果图来看看效果吧! 用python代码画爱心的思路是怎样的? 1.怎么画心形曲线 2.怎么填满心 ...

  10. 利用snowfall.jquery.js实现爱心满屏飞

    小颖在上一篇一步一步教你用CSS画爱心中已经分享一种画爱心的方法,这次再分享一种方法用css画爱心,并利用snowfall.jquery.js实现爱心满屏飞的效果. 第一步: 利用伪元素before和 ...

随机推荐

  1. P5731 蛇形方阵

    P5731 [深基5.习6]蛇形方阵 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) //为什么用动态二维数组 --->To play to user's input, but ...

  2. 浅谈Redis与分布式锁

    为什么需要分布式锁 Redis如何实现分布式锁 如何避免死锁? 锁被别人释放怎么办? 锁过期时间不好评估怎么办? Redlock 真的安全吗 为什么要在多个实例上加锁? 为什么大多数实例加锁成功,才算 ...

  3. office图标变白新的处理方法

    https://www.haozhuangji.com/xtjc/133013759.html 一般搜索得到的处理方式与上面链接的处理方式差不多,都是通过安装wps或者修改注册表来实现的. 本文是我在 ...

  4. R7-3 汉诺(Hanoi)塔问题

    R7-3 汉诺(Hanoi)塔问题 分数 20 全屏浏览题目 切换布局 作者 张高燕 单位 浙大城市学院 古代某寺庙中有一个梵塔,塔内有3个座A.B和C,座A上放着64个大小不等的盘,其中大盘在下,小 ...

  5. js中常用的运算符

    1. ?. 链接运算符 特性: 一旦遇到空置就会终止 例子: let name = obj?.name persion.getTip?.() // 没有getTip 方法则不会执行 2. ?? 空值合 ...

  6. nginx的301与302跳转详细配置教程

    什么是301跳转 301跳转也叫301重定向,也叫301转向,也叫301永久重定向,是网站建设过程中的一个功能.一般用于2个域名指向同一个网站. 一般来说,利用跳转,对网站的排名不会有影响.但不会转移 ...

  7. 38.Ribbon

    Ribbon默认是懒加载,所以初次请求时间最长,后续请求会变快,可以通过修改为饥饿加载 ribbon.eager-load.enabled=true ribbon.eager-load.clients ...

  8. 0xc0000142怎么修复

    0xc0000142怎么修复 参考链接 https://jingyan.baidu.com/article/4d58d54102f3d29dd4e9c0b1.html

  9. js 判断表格的值

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  10. golang中自带base64编码和解码

    package main import ( "encoding/base64" "fmt" "log" ) func main() { in ...