<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<style>
:root {
--title-size: 4em;
--signature-size: 1.5em;
}
body {
background: #ffe6f2;
margin: 0;
height: 100vh;
overflow: hidden;
touch-action: manipulation;
}
.container {
position: relative;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.title-box {
position: relative;
text-align: right;
max-width: 90%;
}
.title {
font-size: var(--title-size);
color: #ff3366;
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
font-family: 'Arial', sans-serif;
margin: 0;
line-height: 1.2;
word-break: keep-all;
}
.signature {
font-size: var(--signature-size);
color: #ff6699;
font-style: italic;
margin-top: 0.5em;
position: relative;
right: 0;
}
.heart {
position: absolute;
z-index: 1;
animation: float 3s infinite;
opacity: 0;
pointer-events: none;
}
.heart::before,
.heart::after {
content: '';
position: absolute;
width: 20px;
height: 32px;
background: #ff3366;
border-radius: 20px 20px 0 0;
transform: rotate(-45deg);
transform-origin: 0 100%;
}
.heart::after {
left: 20px;
transform: rotate(45deg);
transform-origin: 100% 100%;
}
@keyframes float {
0% { transform: translateY(0); opacity: 0; }
50% { opacity: 0.7; }
100% { transform: translateY(-100vh); opacity: 0; }
}
@media (max-width: 768px) {
:root {
--title-size: 2.5em;
--signature-size: 1.2em;
}
.title-box {
margin-right: 10px;
}
.heart::before,
.heart::after {
width: 15px;
height: 24px;
}
}
@media (max-width: 480px) {
:root {
--title-size: 2em;
--signature-size: 1em;
}
}
</style>
</head>
<body>
<div class="container">
<div class="title-box">
<h1 class="title">情人节快乐</h1>
<div class="signature">to SUN</div>
</div>
</div>
<script>
function createHeart() {
const heart = document.createElement('div');
heart.className = 'heart';
// 响应式爱心大小
const baseSize = window.innerWidth > 768 ? 30 : 20;
const size = Math.random() * baseSize + (baseSize/2);
heart.style.width = size + 'px';
heart.style.height = size + 'px';
// 控制生成区域(两侧各留15%空间)
heart.style.left = 15 + Math.random() * 70 + '%';
heart.style.animationDelay = Math.random() * 2 + 's';
document.body.appendChild(heart);
setTimeout(() => heart.remove(), 3000);
}
// 响应式生成频率
function getInterval() {
return window.innerWidth > 768 ? 300 : 500;
}
let heartInterval = setInterval(createHeart, getInterval());
// 窗口大小变化时调整
window.addEventListener('resize', () => {
clearInterval(heartInterval);
heartInterval = setInterval(createHeart, getInterval());
});
</script>
</body>
</html>
index.html
style.css
index.js
index.html