잠시만 기다려주세요...

利用 sass 和 box-shadow 实现星空背景

이 문서는 언어를 선택할 수 있습니다
成都2024년 9월 23일 월 오전 1시1.26k235예상 읽는 시간 2 분
QR 코드
즐겨찾기Ctrl + D
html
        <div>
    <div class="astral_1" />
    <div class="astral_2" />
    <div class="astral_3" />
    <div class="astral_4" />
    <div class="astral_5" />
</div>

    
scss
        <style scoped lang="scss">

@use "sass:math";
@function getShadows($n) {
    $result: '#{random(100)}vw #{random(100)}vh 0 #fff';
    @for $i from 2 through floor($n) {
        $result: '#{$result}, #{random(100)}vw #{random(100)}vh 0 #fff';
    }
    @return unquote($result);
}

$duration: 600s;
$num: 1000;
@for $i from 1 through 5 {
    $duration: math.div($duration, 2);
    $num: math.div($num, 2);
    .astral_#{$i} {
        z-index: -1;
        position: fixed;
        top: 0;
        left: 0;
        width: #{$i}px;
        height: #{$i}px;
        border-radius: 50%;
        box-shadow: getShadows($num);
        animation: moveUp $duration linear infinite;
        &::after {
            content: '';
            position: absolute;
            top: 100vh;
            left: 0;
            width: inherit;
            height: inherit;
            border-radius: inherit;
            box-shadow: inherit;
        }
    }
}

@keyframes moveUp {
    to {
        transform: translateY(-100vh);
    }
}

</style>