[SCSS] Milky Way effect

@use 'sass:math';
@use 'sass:string';

html {
  background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
  height: 100%;
  width: 100%;
  overflow: hidden;
}

@function createShadow($n) {
  $shadow: '#{math.random(100)}vw #{math.random(100)}vh #fff';
  @for $i from 2 through $n {
    $shadow: '#{$shadow}, #{math.random(100)}vw #{math.random(100)}vh #fff';
  }
  @return string.unquote($shadow);
}

$count: 1000;
$duration: 2000s;
@for $i from 1 through 5 {
  $count: math.floor(calc($count / 2));
  $duration: math.floor(calc($duration / 2));
.layer#{$i} {
  $size: #{$i}px;
  position: fixed;
  width: $size;
  height: $size;
  border-radius: 50%;
  left: 0;
  top: 0;
  box-shadow: createShadow($count);
  animation: moveUp $duration linear infinite;
  &::after {
    content: '';
    width: inherit;
    height: inherit;
    position: fixed;
    top: 100vh;
    left: 0;
    border-radius: inherit;
    box-shadow: inherit;
  }
}
}



@keyframes moveUp {
  100% {
    transform: translateY(-100vh);
  }
}
 <body>
     <div class="layer1"></div>
     <div class="layer2"></div>
     <div class="layer3"></div>
     <div class="layer4"></div>
     <div class="layer5"></div>
  </body>
posted @ 2025-02-15 23:33  Zhentiw  阅读(5)  评论(0)    收藏  举报