<!DOCTYPE html>
<html lang="zh-***">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS3外星飞船UFO动画特效</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: linear-gradient(to bottom, #000428, #004e92);
min-height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
.scene {
position: relative;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
/* 星空背景 */
.stars {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle var(--duration) infinite ease-in-out;
opacity: 0;
}
@keyframes twinkle {
0%, 100% { opacity: 0; }
50% { opacity: var(--opacity); }
}
/* UFO主体 */
.ufo {
position: relative;
width: 200px;
height: 80px;
z-index: 10;
animation: float 6s ease-in-out infinite;
}
/* UFO顶部 */
.ufo-top {
position: absolute;
width: 200px;
height: 60px;
background: radial-gradient(ellipse at center, #00ff*** 0%, #009688 70%);
border-radius: 100px 100px 0 0;
top: 0;
box-shadow: 0 0 20px rgba(0, 255, 204, 0.6);
}
/* UFO底部 */
.ufo-bottom {
position: absolute;
width: 160px;
height: 30px;
background: radial-gradient(ellipse at center, #4d4d4d 0%, #1a1a1a 70%);
border-radius: 0 0 80px 80px;
bottom: 0;
left: 20px;
box-shadow: 0 0 10px rgba(0, 255, 204, 0.4);
}
/* UFO底部灯光 */
.ufo-light {
position: absolute;
width: 120px;
height: 40px;
background: radial-gradient(ellipse at center, rgba(0, 255, 204, 0.8) 0%, rgba(0, 255, 204, 0) 70%);
border-radius: 50%;
bottom: -20px;
left: 40px;
z-index: -1;
animation: light-pulse 2s infinite alternate;
}
/* UFO窗户 */
.ufo-window {
position: absolute;
width: 40px;
height: 20px;
background: radial-gradient(ellipse at center, #aaffff 0%, #00a2ff 100%);
border-radius: 20px;
top: 20px;
left: 80px;
box-shadow: 0 0 10px rgba(170, 255, 255, 0.8);
}
/* 光束 */
.beam {
position: absolute;
width: 60px;
height: 300px;
background: linear-gradient(to bottom, rgba(0, 255, 204, 0.6) 0%, rgba(0, 255, 204, 0) 100%);
border-radius: 30px;
bottom: -300px;
left: 70px;
z-index: -1;
transform-origin: top center;
animation: beam 4s infinite alternate;
filter: blur(5px);
}
/* 小外星人 */
.alien {
position: absolute;
width: 30px;
height: 40px;
bottom: -280px;
left: 85px;
z-index: 5;
animation: alien-float 4s infinite ease-in-out;
opacity: 0;
animation-delay: 2s;
}
.alien-head {
position: absolute;
width: 30px;
height: 20px;
background: #00ff***;
border-radius: 15px 15px 0 0;
top: 0;
box-shadow: 0 0 5px rgba(0, 255, 204, 0.8);
}
.alien-body {
position: absolute;
width: 30px;
height: 20px;
background: #00***99;
border-radius: 0 0 10px 10px;
bottom: 0;
}
.alien-eye {
position: absolute;
width: 8px;
height: 8px;
background: black;
border-radius: 50%;
top: 6px;
}
.alien-eye.left {
left: 6px;
}
.alien-eye.right {
right: 6px;
}
/* 动画 */
@keyframes float {
0%, 100% {
transform: translateY(0) rotate(0deg);
}
50% {
transform: translateY(-30px) rotate(5deg);
}
}
@keyframes light-pulse {
0% {
transform: scale(1);
opacity: 0.8;
}
100% {
transform: scale(1.2);
opacity: 0.4;
}
}
@keyframes beam {
0% {
transform: scaleY(0.8);
opacity: 0;
}
50% {
opacity: 0.6;
}
100% {
transform: scaleY(1);
opacity: 0.3;
}
}
@keyframes alien-float {
0%, 30% {
transform: translateY(0);
opacity: 0;
}
40% {
opacity: 1;
}
70% {
transform: translateY(-100px);
opacity: 1;
}
100% {
transform: translateY(-100px);
opacity: 0;
}
}
/* 地面 */
.ground {
position: absolute;
width: 100%;
height: 100px;
background: linear-gradient(to bottom, #003366, #000);
bottom: 0;
z-index: 2;
}
/* 标题 */
.title {
position: absolute;
top: 30px;
color: #00ff***;
font-size: 24px;
text-shadow: 0 0 10px rgba(0, 255, 204, 0.7);
z-index: 20;
}
/* 链接 */
.link {
position: absolute;
bottom: 30px;
color: #00ff***;
font-size: 14px;
text-decoration: none;
z-index: 20;
padding: 8px 16px;
border: 1px solid #00ff***;
border-radius: 20px;
transition: all 0.3s;
}
.link:hover {
background: rgba(0, 255, 204, 0.2);
box-shadow: 0 0 15px rgba(0, 255, 204, 0.5);
}
</style>
</head>
<body>
<div class="scene">
<h1 class="title">CSS3 UFO 动画特效</h1>
<!-- 星空背景 -->
<div class="stars" id="stars"></div>
<!-- UFO -->
<div class="ufo">
<div class="ufo-top"></div>
<div class="ufo-bottom"></div>
<div class="ufo-light"></div>
<div class="ufo-window"></div>
<div class="beam"></div>
<div class="alien">
<div class="alien-head">
<div class="alien-eye left"></div>
<div class="alien-eye right"></div>
</div>
<div class="alien-body"></div>
</div>
</div>
<!-- 地面 -->
<div class="ground"></div>
</div>
<script>
// 创建星星
const starsContainer = document.getElementById('stars');
const starCount = 100;
for (let i = 0; i < starCount; i++) {
const star = document.createElement('div');
star.classList.add('star');
// 随机位置
const x = Math.random() * 100;
const y = Math.random() * 100;
// 随机大小
const size = Math.random() * 3 + 1;
// 随机动画参数
const duration = Math.random() * 5 + 3;
const opacity = Math.random() * 0.8 + 0.2;
const delay = Math.random() * 5;
star.style.left = `${x}%`;
star.style.top = `${y}%`;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
star.style.setProperty('--duration', `${duration}s`);
star.style.setProperty('--opacity', opacity);
star.style.animationDelay = `${delay}s`;
starsContainer.appendChild(star);
}
// 鼠标移动时UFO跟随效果
document.addEventListener('mousemove', (e) => {
const ufo = document.querySelector('.ufo');
const x = e.clientX / window.innerWidth;
const y = e.clientY / window.innerHeight;
const moveX = (x - 0.5) * 40;
const moveY = (y - 0.5) * 40;
ufo.style.transform = `translate(${moveX}px, ${moveY - 30}px) rotate(${moveX / 10}deg)`;
});
</script>
</body>
</html>