<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>点击弹出爱心</title>
<style>
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
cursor: pointer;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.heart {
position: absolute;
width: 20px;
height: 20px;
background-color: red;
transform: rotate(45deg);
pointer-events: none;
animation: heartAnimation 1s ease-out;
}
.heart:before, .heart:after {
content: '';
position: absolute;
width: 20px;
height: 20px;
background-color: red;
border-radius: 50%;
}
.heart:before {
top: -10px;
left: 0;
}
.heart:after {
top: 0;
left: -10px;
}
@keyframes heartAnimation {
0% {
transform: rotate(45deg) scale(0.8);
opacity: 1;
}
100% {
transform: rotate(45deg) scale(1.5);
opacity: 0;
}
}
.footer {
position: fixed;
bottom: 10px;
width: 100%;
text-align: center;
color: #888;
}
.footer a {
color: #ff69b4;
text-decoration: none;
}
</style>
</head>
<body>
<script>
document.addEventListener('click', function(e) {
// 创建爱心元素
const heart = document.createElement('div');
heart.className = 'heart';
// 设置爱心位置为点击位置
heart.style.left = (e.clientX - 10) + 'px';
heart.style.top = (e.clientY - 10) + 'px';
// 随机颜色
const colors = ['#ff0000', '#ff69b4', '#ff1493', '#ff00ff', '#ff6347'];
const randomColor = colors[Math.floor(Math.random() * colors.length)];
heart.style.backgroundColor = randomColor;
heart.querySelectorAll(':before, :after').forEach(el => {
el.style.backgroundColor = randomColor;
});
// 添加到页面
document.body.appendChild(heart);
// 动画结束后移除元素
setTimeout(() => {
heart.remove();
}, 1000);
});
</script>
</body>
</html>
1879

被折叠的 条评论
为什么被折叠?



