console
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>爱心祝福</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{overflow:hidden;background:#000}
.box{
position:absolute;
padding:10px 14px;
border-radius:12px;
font-family:"Microsoft Yahei",sans-serif;
font-size:16px;
white-space:nowrap;
box-shadow:0 2px 12px #0003;
}
</style>
</head>
<body>
<script>
const tips = ['学业有成', '好好爱自己', '好好吃饭', '保持好心情',
'身体健康', '顺顺利利', '别熬夜', '天凉了多穿衣服'];
const colors = ['#ffc0cb','#add8e6','#90ee90','#fffacd','#ff69b4','#87ceeb'];
const w = window.innerWidth;
const h = window.innerHeight;
function getHeartPoints(n){
let arr=[];
for(let i=0;i<n;i++){
let t = i/n * 2 * Math.PI;
let x = 16 * Math.pow(Math.sin(t),3);
let y = 13*Math.cos(t) -5*Math.cos(2*t)-2*Math.cos(3*t)-Math.cos(4*t);
let sx = w/2 + x*12;
let sy = h/2 - y*12;
arr.push({x:sx,y:sy})
}
return arr;
}
function createBox(x,y,text){
let div = document.createElement('div');
div.className="box";
div.innerText = text;
div.style.left = x+'px';
div.style.top = y+'px';
div.style.background = colors[Math.floor(Math.random()*colors.length)];
document.body.appendChild(div);
return div;
}
(async function run(){
const points = getHeartPoints(100);
let list = [];
for(let i=0;i<points.length;i++){
let txt = i === points.length-1 ? "我喜欢你" : tips[Math.floor(Math.random()*tips.length)];
let el = createBox(points[i].x, points[i].y, txt);
list.push(el);
await sleep(30);
}
await sleep(1000);
list.forEach(el=>el.remove());
let all = [];
for(let i=0;i<80;i++){
let tx = tips[Math.floor(Math.random()*tips.length)];
let rx = Math.random()*(w-160);
let ry = Math.random()*(h-80);
let el = createBox(rx,ry,tx);
all.push(el);
await sleep(5);
}
await sleep(10000);
for(let el of all){
el.remove();
await sleep(40);
}
})()
function sleep(ms){
return new Promise(resolve=>setTimeout(resolve,ms))
}
</script>
</body>
</html>