爱心代码_HTML
直接上效果
<!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的更多相关文章
- 纯css爱心代码-最近超级火的打火机与公主裙中的爱心代码(简易版)
theme: cyanosis 最近打火机与公主裙中的爱心代码超级火,看着特别心动,让俺用css来写个简易版!!! 先看效果: 代码拆解: 主要是分为3大部分 分子颗粒 爱心 动画 代码实现: 分子颗 ...
- Python之——爱心代码参与情人节
一行代码实现输出爱心图,参考https://zhuanlan.zhihu.com/p/23321351 原理: 1.借助数学函数——((x * 0.05) ** 2 + (y * 0.1) ** 2 ...
- 3d爱心代码
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- 用CSS画基本图形
用CSS画基本图形 1.正方形 代码如下: #square { width: 100px; height: 100px; background: red; } 2.长方形 代码如下: #recta ...
- phpcms编辑器添加一键排版控件
CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的 废话不多说,直接说步骤第一步:config.j ...
- 六行python代码的爱心曲线
前些日子在做绩效体系的时候,遇到了一件囧事,居然忘记怎样在Excel上拟合正态分布了,尽管在第二天重新拾起了Excel中那几个常见的函数和图像的做法,还是十分的惭愧.实际上,当时有效偏颇了,忽略了问题 ...
- HTML5 Canvas爱心时钟代码
这是一款数字时钟动画,数字又多个小爱心组成,又何问起整理,随着时间推进,每一秒钟新数字替换旧数字,旧数字离去使用天女散花动画,花是五颜六色的. 查看效果:http://hovertree.com/te ...
- javascript博客爱心特效代码与代码解析
这个鼠标点击出现爱心的特效经常在别的博客里见到,于是我查了度娘后拿来直接用上了. 虽然不知道原作者是谁,但肯定是个大神,只有通过观摩他/她的代码膜拜一下啦. 直接上代码(解析在代码注释里): // 自 ...
- 程序员式优雅表白,教你用python代码画爱心
还能用python代码画爱心?还有这种操作?这是什么原理? 不相信python代码可以画爱心?先来一张效果图来看看效果吧! 用python代码画爱心的思路是怎样的? 1.怎么画心形曲线 2.怎么填满心 ...
- 利用snowfall.jquery.js实现爱心满屏飞
小颖在上一篇一步一步教你用CSS画爱心中已经分享一种画爱心的方法,这次再分享一种方法用css画爱心,并利用snowfall.jquery.js实现爱心满屏飞的效果. 第一步: 利用伪元素before和 ...
随机推荐
- 读后笔记 -- Java核心技术(第11版 卷 II) Chapter5 数据库编程
5.1 JDBC API 1. JDBC (Java Database Connectivity) is an API for interacting with a database in Java. ...
- ucocIII野火
5.1裸机系统 5.1.1 轮询系统 轮询系统即是在裸机编程的时候,先初始化好相关的硬件,然后让主程序在一个死循环里面不断循环,顺序地做各种事情.轮询系统是一种非常简单的软件结构,通常只适用于那些只需 ...
- Vue 使用Lodop进行标签(条码)打印
一.使用到的插件:vue-barcode(vue条形码插件),Lodop打印控件(我这里使用windows64版,所以以此进行举例说明.). 详述:前者(指vue-barcode)针对在前端界面上观察 ...
- win/ubuntu/centos 安装后台监控工具btop
之前linux平台进行后台监控一直是简单的看top,但界面太难看而且需要记的缩写太多而且不直观(对于我来说),后面有尝试替换htop,扩展支持了鼠标操作以及直观监控,但是界面还是难看,今天查找了一下发 ...
- 为什么要有jvm,jvm的作用?
jvm的两个作用:第一.运行并管理java源码文件所生成的Class文件.第二.在不同的操作系统上安装不同的jvm,从而去实现跨平台的一个保障. 一般情况下,即使不熟悉jvm的运行机制,也不影响业务代 ...
- wake on lan sender 2.0.8
局域网 远程关机
- wsl无法创建文件与修改文件
wsl无法创建文件与修改文件 sudo chown -R username /home/your_folder/ 请将用户名换成你的用户名 且目录换成你想要操作的目录
- go组合
package main import "fmt" func main() { aa := []string{"a", "b", " ...
- css 多行隐藏
overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box- ...
- 90、java ftp 读取文件
https://blog.csdn.net/qq_38380025/article/details/80679128