<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我喜欢你❤️</title>
<style>
html,
body {
height: 100%;
padding: 0;
margin: 0;
background: #e4e1bc;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}
.text-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 25px;
font-family: Arial, sans-serif;
text-align: center;
z-index: 1;
}
.question-box {
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 255, 255, 0.8);
border-radius: 10px;
padding: 20px;
text-align: center;
z-index: 1;
width: 300px;
}
.question-box h2 {
margin: 0;
font-size: 24px;
}
.question-box button {
background-color: #de2727;
border: none;
color: white;
padding: 10px 20px;
margin: 10px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.question-box button:hover {
background-color: #b72626;
}
audio {
display: none;
}
</style>
</head>
<body>
<canvas id="pinkboard"></canvas>
<div class="text-overlay">wcy我喜欢你</div>
<div class="question-box" id="questionBox">
<h2>你喜欢我吗?</h2>
<button onclick="handleResponse('喜欢')">喜欢</button>
<button onclick="handleResponse('我追你')">我追你</button>
</div>
<audio id="backgroundMusic" autoplay>
<source src="background.mp4" type="audio/mp4">
Your browser does not support the audio element.
</audio>
<script>
function handleResponse(response) {
alert("你选择了: ‘" + response + "’,真的吗,我好喜欢你呀");
document.getElementById('questionBox').style.display = 'none';
}
window.onload = function () {
var audio = document.getElementById('backgroundMusic');
audio.volume = 0.5;
};
var settings = {
particles: {
length: 500,
duration: 2,
velocity: 100,
effect: -0.75,
size: 30,
},
};
(function () {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function (callback) {
var now = new Date().getTime();
var time = Math.max(0, 16 - (now - lastTime));
var id = window.setTimeout(function () { callback(now + time); }, time);
lastTime = now + time;
return id;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function (id) { clearTimeout(id); };
}
})();
class Point {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
clone() {
return new Point(this.x, this.y);
}
length(length) {
if (length === undefined) {
return Math.sqrt(this.x ** 2 + this.y ** 2);
}
this.normalize();
this.x *= length;
this.y *= length;
return this;
}
normalize() {
const len = this.length();
this.x /= len;
this.y /= len;
return this;
}
}
class Particle {
constructor() {
this.position = new Point();
this.velocity = new Point();
this.acceleration = new Point();
this.age = 0;
}
initialize(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;
}
update(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;
}
draw(context, image) {
const ease = t => (--t) * t * t + 1;
const 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);
}
}
class ParticlePool {
constructor(length) {
this.particles = Array.from({ length }, () => new Particle());
this.firstActive = 0;
this.firstFree = 0;
}
add(x, y, dx, dy) {
this.particles[this.firstFree].initialize(x, y, dx, dy);
this.firstFree = (this.firstFree + 1) % this.particles.length;
if (this.firstActive === this.firstFree) {
this.firstActive = (this.firstActive + 1) % this.particles.length;
}
}
update(deltaTime) {
const { particles, firstActive, firstFree } = this;
for (let i = firstActive; i !== firstFree; i = (i + 1) % particles.length) {
particles[i].update(deltaTime);
}
while (particles[this.firstActive].age >= settings.particles.duration && this.firstActive !== this.firstFree) {
this.firstActive = (this.firstActive + 1) % this.particles.length;
}
}
draw(context, image) {
const { particles, firstActive, firstFree } = this;
for (let i = firstActive; i !== firstFree; i = (i + 1) % particles.length) {
particles[i].draw(context, image);
}
}
}
(function (canvas) {
const context = canvas.getContext('2d');
const particles = new ParticlePool(settings.particles.length);
const particleRate = settings.particles.length / settings.particles.duration;
let time;
function 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
);
}
const image = (function () {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = settings.particles.size;
canvas.height = settings.particles.size;
function to(t) {
const 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;
}
context.beginPath();
let t = -Math.PI;
let point = to(t);
context.moveTo(point.x, point.y);
while (t < Math.PI) {
t += 0.01;
point = to(t);
context.lineTo(point.x, point.y);
}
context.closePath();
context.fillStyle = '#de2727';
context.fill();
context.font = '12px Arial';
context.fillStyle = 'white';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText('love', canvas.width / 2, canvas.height / 2);
const image = new Image();
image.src = canvas.toDataURL();
return image;
})();
function render() {
requestAnimationFrame(render);
const newTime = Date.now() / 1000;
const deltaTime = newTime - (time || newTime);
time = newTime;
context.clearRect(0, 0, canvas.width, canvas.height);
const amount = particleRate * deltaTime;
for (let i = 0; i < amount; i++) {
const pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
const dir = pos.clone().length(settings.particles.velocity);
particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
}
particles.update(deltaTime);
particles.draw(context, image);
}
function onResize() {
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
}
window.onresize = onResize;
setTimeout(function () {
onResize();
render();
}, 10);
})(document.getElementById('pinkboard'));
</script>
</body>
</html>
情人节/七夕/520/表白html代码/包100%成功/不舔/做行动的巨人!
最新推荐文章于 2024-09-16 23:05:35 发布