vue 动画气泡背景

vue2 背景气泡

结构如下
思想如下 一个div 代表一个气泡

<div class="backgroundBubble">
	<div class='bubble'>*10
</div>
利用render函数生成10个div 就不必手写div
后续想要增加气泡增加length的长度
然后样式采用css动画。
  • 注意下面scss调用的数组长度为10,如果想要增加气泡 也要增加数组。
<script>
export default {
  name: 'bubbles',
  data() {
    return {}
  },
  render(h) {
    return h(
      'div',
      {
        class: {
          backgroundBubble: true,
        },
      },
      Array.apply(null, { length: 10 }).map(function () { //这里的length 代表生成几个气泡
        return h('div', {
          class: {
            bubble: true,
          },
        })
      })
    )
  },
}
</script>
<style lang="scss" scoped>
.backgroundBubble {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  $duration: 9s, 6s, 10s, 5.5s, 12s, 6s, 8s, 15s, 9s, 12s; //这里写了10个数组避免没有采用随机数
  $delay: 0.1s, 1.5s, 0s, 1.5s, 0s, 1s, 1s, 0s, 0.5s, 0s;
  @for $i from 1 through length($duration) {
    $item-duration: nth($duration, $i);
    $item-delay: nth($delay, $i);
    $random: random() * 100 + px; // 随机数的气泡大小  刷新会刷新位置与气泡大小
    $left: random() * 100%; // 随机的气泡位置。 可以像上面一样定义成数组
    .bubble:nth-child(#{$i}) {
      left: $left;
      width: $random;
      height: $random;
      animation-duration: $item-duration;
      animation-delay: $item-delay;
    }
  }
}
.bubble {
  position: absolute;
  border-radius: 50%;
  border: 1px solid #fff;
  box-shadow: inset 0 0 6px #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;
  }
}
</style>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值