[网页]:CSS+HTML制作流星背景

16次阅读
没有评论

调试过后的代码如下:

/* 星空背景 */
.starry-sky {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #000000 0%, #0a0a2a 50%, #000000 100%);
    z-index: -2;
    overflow: hidden;
}

/* 基础星星样式 */
.star {
    position: absolute;
    background-color: white;
    border-radius: 70%;
    animation: twinkle linear infinite;
}

.star.small {
    width: 2px;
    height: 2px;
}

.star.medium {
    width: 3px;
    height: 2px;
}

.star.large {
    width: 8px;
    height: 7px;
}

/* 增强的动态流星效果 */
.shooting-star {
    position: absolute;
    width: 120px;  /* 增加长度 */
    height: 2px;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255,255,255,1) 10%,
        rgba(220,240,255,0.9) 30%,
        rgba(150,200,255,0.5) 70%,
        transparent 100%
    );
    transform-origin: left center;
    transform: rotate(-45deg);
    animation: 
        meteor-fly 2s linear infinite,
        meteor-flicker 0.3s ease-in-out infinite;
    z-index: 1;
    filter: drop-shadow(0 0 5px rgba(100,180,255,0.8));
    opacity: 0;
}

/* 流星动画 - 主要飞行轨迹 */
@keyframes meteor-fly {
    0% {
        transform: rotate(-45deg) translateX(-100px) translateY(-100px);
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    70% {
        opacity: 0.8;
    }
    100% {
        transform: rotate(-45deg) translateX(calc(100vw + 100px)) translateY(calc(100vh + 100px));
        opacity: 0;
    }
}

/* 流星闪烁动画 - 增加动态感 */
@keyframes meteor-flicker {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 1; }
}

/* 星星闪烁动画 */
@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

body {
    background: transparent !important;
    font-family: 'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    line-height: 1.6;
}

/* 性能优化 */
@media (prefers-reduced-motion: reduce) {
    .shooting-star {
        animation: none !important;
    }
}

正文完
 0
评论(没有评论)