开学了,不妨试试这串代码,HTML,CSS,JAVASCRIPT
.scene {
width: 100vw;
height: 100vh;
background: linear-gradient(#87CEEB, #E0F6FF);
overflow: hidden;
position: relative;
}
.sun {
width: 80px;
height: 80px;
background: #FFD700;
borderRadius: 50%;
position: absolute;
left: 10%;
top: 10%;
animation: sunRotate 8s infinite linear;
box-shadow: 0 0 40px #FFD700;
}
.school {
width: 300px;
height: 200px;
background: #FF6B6B;
position: absolute;
bottom: 100px;
left: 50%;
transform: translateX(-50%);
border-radius: 20px;
}
.flag {
width: 60px;
height: 40px;
background: #4ECDC4;
position: absolute;
right: -30px;
top: -20px;
animation: wave 2s infinite alternate;
}
.bus {
width: 150px;
height: 80px;
background: #FFD93D;
position: absolute;
bottom: 120px;
right: -200px;
border-radius: 20px;
animation: carEnter 4s forwards;
}
.student {
width: 40px;
height: 60px;
background: #FF9F43;
position: absolute;
bottom: 120px;
opacity: 0;
animation: studentDisembark 2s 4s forwards;
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3em;
color: #FFFFFF;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
opacity: 0;
animation: textPop 2s 6s forwards;
}
@keyframes sunRotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@keyframes carEnter {
0% { right: -200px; }
100% { right: 50%; }
}
@keyframes studentDisembark {
0% { opacity: 0; transform: translateX(0); }
100% { opacity: 1; transform: translateX(-200px); }
}
@keyframes wave {
0% { transform: skew(0deg, 0deg); }
100% { transform: skew(10deg, 5deg); }
}
@keyframes textPop {
0% { opacity: 0; transform: translate(-50%, -50%) scale(0); }
100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
/* 添加更多卡通元素 */
.cloud {
width: 100px;
height: 40px;
background: white;
border-radius: 20px;
position: absolute;
animation: cloudMove 10s linear infinite;
}
.tree {
width: 60px;
height: 100px;
background: #4A934A;
position: absolute;
bottom: 100px;
border-radius: 20px;
}
.flower {
width: 30px;
height: 30px;
position: absolute;
animation: flowerAnim 2s infinite alternate;
}
新学期快乐!
<script>
// 添加动态创建元素
function createBaloons() {
const colors = ['#FF6B6B', '#4ECDC4', '#FFD93D', '#FF9F43'];
for(let i=0; i<8; i++){
const baloon = document.createElement('div');
baloon.style.cssText = `
width: 30px;
height: 40px;
background: ${colors[i%4]};
position: absolute;
bottom: -50px;
left: ${10 + i*12}%;
border-radius: 50%;
animation: baloonRise ${4 + i/2}s ${i*0.2}s linear forwards;
`;
document.querySelector('.scene').appendChild(baloon);
}
}
// 初始化动画
setTimeout(() => {
createBaloons();
}, 2000);
</script>