生日礼物或表白网页
介绍
爱心代码已经有人网上发过,我就在他基础上加了点文案提示和背景音乐~
这是一个特别的网页,它可以作为生日礼物或者表白的方式。通过点击屏幕,可以播放音乐并夹带着一些暖心的文字,带来愉悦的体验。你可以将这个网页分享给你的朋友或者爱人,让他们感受到你的关怀和爱意。
网页特点
- 点击屏幕即可播放音乐
- 配有粉色背景和浪漫气息的动画效果
- 文字内容包含了一系列暖心的表白和祝福语句
- 网页采用简洁的设计和动画,使得体验更加愉悦
使用方法
只需将网页链接分享给对方,在浏览器中打开页面并点击屏幕,便可感受到这份特别的祝福和表白。
技术细节
- 该网页采用HTML、CSS和JavaScript编写
- 使用Canvas元素实现了粒子动画效果
- 通过点击事件控制音乐的播放
- 采用了自适应布局,适配多种设备屏幕尺寸
参考链接
通过上述Markdown文档,你可以简单地介绍你的生日礼物或表白网页,并提供相关的链接以供他人查看与使用。祝愿你的网页能够为人们带来美好的体验!
电脑效果
具体代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
🥰
</title>
<link rel="shortcut icon" href="https://img.icons8.com/?size=48&id=SkbzwdwhI2sy&format=png"
type="image/x-icon">
<style>
html, body { height: 100%; padding: 0; margin: 0; background: #000; overflow:
hidden; } canvas { position: absolute; width: 100%; height: 100%; } .love-text
{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
opacity: 0; font-size: 14px; padding-bottom: 80px; color: #ea80b0; font-family:
"Arial", sans-serif; transition: opacity 1s ease-in-out; white-space: nowrap;
overflow: hidden; font-weight: bold; z-index: 1; } .fade-in { opacity:
1; }
</style>
</head>
<body>
<script>
var audio;
function playMusic() {
if (!audio || audio.paused) {
audio = new Audio('./love.mp3');
audio.play();
}
}
document.addEventListener('click',
function() {
playMusic();
});
</script>
<canvas id="pinkboard">
</canvas>
<p id="love-text" class="love-text">
</p>
<script>
var loveTexts = ["🦄", "停...@点击屏幕播放音乐吧", "我是 Abdureyim.", "是一个普普通通程序员,但对生活充满热爱的程序员...6", "如果你看到这条消息不妨跟我说一声...", "毕竟我想...", "有机会耳机分你一个 然后开启心动模式", "其实别人每次聊到你的时候我都有偷偷的认真听哦.", "也许我词不达意 但我很开心遇见你", "“在抬不起头的日子,他是唯一的盼头”", "我总爱跟你谈及宇宙温柔橘子汽水味儿的风和蓝色的落日.", "其实我不太懂喜欢可我想走向你。", "匆匆一瞥的激动 回忆多次也是会开心", "我今天过的很开心,喜欢的小猫睡着了欢迎听我的碎碎念,你那的天气如何呢?", "草稿纸上不只是数学演算公式 还有对我来说很重要的人的名字", "你这件衣服我喜欢你可以发链接给我嘛", "你知道吗 在这路遥马急的人间 真的有人把爱意藏了好多年", "我们曾在高朋满座中,将隐晦爱意说到最尽兴", "听别叫我达芬奇的1分17秒。", "我要把可爱和温柔都设置成仅你可见", "我给你推荐几部电影吧\n喜剧之王\n欢乐喜剧人\n你的名字", "你什么时候会明白 我每天给你发的生活琐碎都是在表达爱意", "请允许我成为你的夏季。", "偷偷许愿“她的身边不要出现其他男孩子”", "👽", "对于爱情而言,也许我没有别人有的勇气...", "...保重.", "❤️"];
var loveTextElement = document.getElementById("love-text");
var currentIndex = 0;
function showNextLoveText() {
loveTextElement.innerHTML = loveTexts[currentIndex];
loveTextElement.style.opacity = 1;
currentIndex++;
if (currentIndex >= loveTexts.length) {
currentIndex = 0;
}
setTimeout(hideLoveText, 3000);
}
function hideLoveText() {
loveTextElement.style.opacity = 0;
setTimeout(showNextLoveText, 1000);
}
loveTextElement.style.opacity = 0;
showNextLoveText();
</script>
<script>
var settings = {
particles: {
length: 500,
duration: 2,
velocity: 100,
effect: -0.75,
size: 32
},
}; (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);
}
}
})();
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;
})();
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;
})();
var ParticlePool = (function() {
var particles, firstActive = 0,
firstFree = 0,
duration = settings.particles.duration;
function ParticlePool(length) {
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);
firstFree++;
if (firstFree == particles.length) {
firstFree = 0;
}
if (firstActive == firstFree) {
firstActive++;
}
if (firstActive == particles.length) {
firstActive = 0;
}
};
ParticlePool.prototype.update = function(deltaTime) {
var i;
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);
}
}
while (particles[firstActive].age >= duration && firstActive != firstFree) {
firstActive++;
if (firstActive == particles.length) {
firstActive = 0;
}
}
};
ParticlePool.prototype.draw = function(context, image) {
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;
})(); (function(canvas) {
var context = canvas.getContext('2d');
var particles = new ParticlePool(settings.particles.length);
var particleRate = settings.particles.length / settings.particles.duration;
var 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);
}
var image = (function() {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.width = settings.particles.size;
canvas.height = settings.particles.size;
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;
}
context.beginPath();
var t = -Math.PI;
var 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 = '#ea80b0';
context.fill();
var image = new Image();
image.src = canvas.toDataURL();
return image;
})();
function render() {
requestAnimationFrame(render);
var newTime = new Date().getTime() / 1000;
var deltaTime = newTime - (time || newTime);
time = newTime;
context.clearRect(0, 0, canvas.width, canvas.height);
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);
}
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>