<!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>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #1a0033;
overflow: hidden;
font-family: 'Arial', sans-serif;
}
.scene {
position: relative;
width: 100%;
height: 100%;
}
.gift-box {
position: absolute;
width: 200px;
height: 150px;
background: #8B0000;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 10px;
box-shadow: 0 10px 20px rgba(0,0,0,0.5);
cursor: pointer;
z-index: 2;
transition: all 0.3s ease;
}
.gift-box:hover {
transform: translate(-50%, -50%) scale(1.05);
}
.gift-lid {
position: absolute;
width: 220px;
height: 40px;
background: #FF0000;
top: -40px;
left: -10px;
border-radius: 10px 10px 0 0;
box-shadow: 0 -5px 10px rgba(0,0,0,0.3);
transform-origin: bottom center;
}
.gift-bow {
position: absolute;
width: 60px;
height: 60px;
background: #4B0082;
top: -70px;
left: 70px;
border-radius: 50%;
box-shadow: 0 0 10px rgba(75,0,130,0.8);
}
.gift-bow::before, .gift-bow::after {
content: '';
position: absolute;
width: 80px;
height: 20px;
background: #4B0082;
border-radius: 10px;
}
.gift-bow::before {
top: 20px;
left: -10px;
transform: rotate(45deg);
}
.gift-bow::after {
top: 20px;
left: -10px;
transform: rotate(-45deg);
}
.gift-content {
position: absolute;
width: 180px;
height: 130px;
background: #FF8C00;
top: 10px;
left: 10px;
border-radius: 5px;
overflow: hidden;
display: none;
}
.ghost {
position: absolute;
width: 60px;
height: 80px;
background: rgba(255,255,255,0.9);
border-radius: 50% 50% 0 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
}
.ghost::before {
content: '';
position: absolute;
width: 20px;
height: 20px;
background: rgba(255,255,255,0.9);
border-radius: 50%;
top: 30px;
left: -10px;
}
.ghost::after {
content: '';
position: absolute;
width: 20px;
height: 20px;
background: rgba(255,255,255,0.9);
border-radius: 50%;
top: 30px;
right: -10px;
}
.ghost-eye {
position: absolute;
width: 10px;
height: 10px;
background: #000;
border-radius: 50%;
top: 20px;
}
.ghost-eye.left {
left: 15px;
}
.ghost-eye.right {
right: 15px;
}
.ghost-mouth {
position: absolute;
width: 30px;
height: 15px;
border-bottom: 3px solid #000;
border-radius: 0 0 50% 50%;
bottom: 15px;
left: 15px;
}
.bat {
position: absolute;
width: 40px;
height: 20px;
background: #333;
border-radius: 50%;
display: none;
}
.bat::before, .bat::after {
content: '';
position: absolute;
width: 30px;
height: 50px;
background: #333;
border-radius: 50% 50% 0 0;
top: -15px;
}
.bat::before {
left: -25px;
transform: rotate(-30deg);
}
.bat::after {
right: -25px;
transform: rotate(30deg);
}
.spider {
position: absolute;
width: 30px;
height: 30px;
background: #000;
border-radius: 50%;
display: none;
}
.spider-leg {
position: absolute;
width: 30px;
height: 5px;
background: #000;
border-radius: 5px;
}
.sparkle {
position: absolute;
width: 10px;
height: 10px;
background: #FFF;
border-radius: 50%;
filter: blur(1px);
display: none;
}
/* 插入的链接样式 */
.custom-link {
position: fixed;
bottom: 20px;
right: 20px;
color: rgba(255,255,255,0.7);
text-decoration: none;
font-size: 14px;
background: rgba(0,0,0,0.3);
padding: 8px 15px;
border-radius: 20px;
z-index: 10;
transition: all 0.3s ease;
}
.custom-link:hover {
color: white;
background: rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<div class="scene">
<div class="gift-box">
<div class="gift-lid"></div>
<div class="gift-bow"></div>
<div class="gift-content">
<div class="ghost">
<div class="ghost-eye left"></div>
<div class="ghost-eye right"></div>
<div class="ghost-mouth"></div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// 创建万圣节元素
function createHalloweenElements() {
const elements = ['bat', 'spider', 'sparkle'];
const colors = ['#FF0000', '#FF8C00', '#4B0082', '#8B0000'];
for (let i = 0; i < 15; i++) {
const type = elements[Math.floor(Math.random() * elements.length)];
const element = $(`<div class="${type}"></div>`);
// 随机位置
const left = Math.random() * 100;
const top = Math.random() * 100;
element.css({
left: `${left}%`,
top: `${top}%`,
transform: `scale(${Math.random() * 0.5 + 0.5})`
});
if (type === 'spider') {
// 添加蜘蛛腿
for (let j = 0; j < 8; j++) {
const leg = $('<div class="spider-leg"></div>');
const angle = j * (360 / 8);
const length = Math.random() * 20 + 15;
leg.css({
left: '15px',
top: '15px',
transform: `rotate(${angle}deg) translateX(15px)`,
width: `${length}px`,
'transform-origin': 'left center'
});
element.append(leg);
}
}
if (type === 'sparkle') {
element.css({
'background-color': colors[Math.floor(Math.random() * colors.length)]
});
}
$('.scene').append(element);
}
}
// 礼物盒点击事件
$('.gift-box').click(function() {
// 打开盒子
$(this).css('background', '#8B0000');
$('.gift-lid').css('transform', 'rotate(-15deg)');
$('.gift-bow').css('transform', 'translateY(-20px)');
// 显示内容
setTimeout(function() {
$('.gift-content').fadeIn(500);
$('.ghost').fadeIn(500).css({
'animation': 'float 3s ease-in-out infinite'
});
// 显示万圣节元素
createHalloweenElements();
$('.bat, .spider, .sparkle').each(function() {
$(this).fadeIn(1000).css({
'animation': `fly${Math.floor(Math.random() * 3) + 1} ${Math.random() * 5 + 5}s linear infinite`
});
});
}, 500);
// 禁用再次点击
$(this).off('click');
});
// 添加动画关键帧
$('<style>')
.text(`
@keyframes float {
0%, 100% { transform: translate(-50%, -50%) translateY(0); }
50% { transform: translate(-50%, -50%) translateY(-20px); }
}
@keyframes fly1 {
0% { transform: translate(0, 0) rotate(0deg); }
100% { transform: translate(100vw, -100vh) rotate(360deg); }
}
@keyframes fly2 {
0% { transform: translate(0, 0) rotate(0deg); }
100% { transform: translate(-100vw, -100vh) rotate(-360deg); }
}
@keyframes fly3 {
0% { transform: translate(0, 0) rotate(0deg); }
50% { transform: translate(50vw, -50vh) rotate(180deg); }
100% { transform: translate(0, -100vh) rotate(360deg); }
}
`)
.appendTo('head');
});
</script>
</body>
</html>
1564

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



