<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery五彩缤纷心形冒泡动画特效</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #000;
height: 100vh;
cursor: pointer;
}
.heart {
position: absolute;
pointer-events: none;
transform: translate(-50%, -50%);
animation: float 4s ease-in-out infinite;
}
.heart:before, .heart:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background: currentColor;
border-radius: 50%;
}
.heart:before {
left: -50%;
}
.heart:after {
top: -50%;
}
@keyframes float {
0% {
transform: translate(-50%, -50%) scale(0.5);
opacity: 1;
}
100% {
transform: translate(-50%, -150%) scale(1);
opacity: 0;
}
}
.message {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: Arial, sans-serif;
text-align: center;
z-index: 100;
}
.message a {
color: #ff69b4;
text-decoration: none;
}
.message a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="message">
<h1>五彩缤纷心形冒泡特效</h1>
<p>点击屏幕任意位置创建心形泡泡</p>
</div>
<script>
$(document).ready(function() {
// 颜色数组
const colors = [
'#ff0000', '#ff69b4', '#ff1493', '#ff00ff',
'#9400d3', '#4b0082', '#0000ff', '#00bfff',
'#00ffff', '#00ff7f', '#7cfc00', '#ffff00',
'#ffa500', '#ff8c00', '#ff4500'
];
// 点击事件
$(document).on('click', function(e) {
createHeart(e.pageX, e.pageY);
});
// 自动生成心形(可选)
setInterval(function() {
if (Math.random() > 0.7) {
const x = Math.random() * $(window).width();
const y = $(window).height() + 50;
createHeart(x, y);
}
}, 300);
// 创建心形函数
function createHeart(x, y) {
const heart = $('<div class="heart"></div>');
const size = Math.random() * 30 + 20;
const color = colors[Math.floor(Math.random() * colors.length)];
heart.css({
left: x,
top: y,
width: size + 'px',
height: size + 'px',
color: color,
animationDuration: (Math.random() * 3 + 2) + 's'
});
$('body').append(heart);
// 动画结束后移除元素
setTimeout(function() {
heart.remove();
}, 4000);
}
});
</script>
</body>
</html>

3071

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



