scss实现随机气泡大小,left百分比位置

67 阅读1分钟

scss实现随机气泡大小,left百分比位置

@for $i from 1 through 7 {
  $size: random(40) + 30;
  $duration: random(8) + 4;
  $delay: random(3) + 1;
  $left: random(80) + 10%;

  .bubble:nth-child(#{$i}) {
    width: $size + px;
    height: $size + px;
    animation-duration: $duration + s;
    animation-delay: $delay + s;
    left: $left;
  }
}

气泡使用box-shadow: inset 0 0 8px #fff;

.bubble {
  position: absolute;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: inset 0 0 8px #fff;
  animation: flutter 10s infinite;
  opacity: 0;
}
<template>
  <div class="bubble_box">
    <div class="bubble" v-for="item in bubbles" :key="item"></div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'

const bubbles = reactive([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
</script>
<style lang="scss" scoped>
.bubble_box {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -10;
  background-image: linear-gradient(
    180deg,
    rgb(78, 168, 241),
    rgb(37, 91, 241)
  );
}
.bubble {
  position: absolute;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: inset 0 0 8px #fff;
  animation: flutter 10s infinite;
  opacity: 0;
}
@keyframes flutter {
  0% {
    transform: translateX(0);
    bottom: -100px;
    opacity: 1;
  }
  50% {
    transform: translateX(100px);
    opacity: 0.5;
  }

  100% {
    transform: translateX(0px);
    bottom: 100%;
    opacity: 0;
  }
}
@for $i from 1 through 7 {
  $size: random(40) + 30;
  $duration: random(8) + 4;
  $delay: random(3) + 1;
  $left: random(80) + 10%;

  .bubble:nth-child(#{$i}) {
    width: $size + px;
    height: $size + px;
    animation-duration: $duration + s;
    animation-delay: $delay + s;
    left: $left;
  }
}
</style>