vue的列表加载过渡动画

18 篇文章 0 订阅

在这里插入图片描述

重点代码:

html :   :class="`animation-${index+1}`"
css :
   $grid-columns: 10;
  @for $i from 1 through $grid-columns {
    $time: ($i * 100+200) + ms;
    .animation-#{$i} {
      animation-delay: $time;
    }
  }

完整代码如下:

<template>
  <div class="content">
    <div v-for="(item,index) in new Array(10)" :key="index" class="box" :class="`animation-${index+1}`"> </div>
  </div>
</template>
<script>
export default {
  name: "listLoadAnimation",
  components: {},
  methods: {}
};
</script>

<style lang="scss" scoped>
$grid-columns: 10; 
.content {
  padding: 0.3rem;
  .box {
    width: 100%;
    height: 2rem;
    background: red;
    margin-bottom: 0.3rem;
    box-shadow: 0 0 0.2rem rgba($color: #000000, $alpha: 1);
  }

  @for $i from 1 through $grid-columns {
    $time: ($i * 100+200) + ms;
    .animation-#{$i} {
      transition: all 0.5s linear;
      animation-name: toTop; // toBottom
      animation-duration: 0.5s; // 注释掉 会没有动画 就是帕帕一帧一帧的出来
      animation-fill-mode: both;
      animation-delay: $time;
    }
  }
}
// 方向 下-->上
@keyframes toTop {
  0% {
    opacity: 0;
    transform: translate3d(0, 100%, 0);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}
// 方向 上-->下
@keyframes toBottom {
  0% {
    opacity: 0;
    transform: translate3d(0, -100%, 0);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

</style>

  • 这里再次介绍一个 Sass if else 的用法(针对上述的代码修改)
  @for $i from 1 through $grid-columns {
    $time: ($i * 100+200) + ms;
    .animation-#{$i} {
      transition: all 0.5s linear;
      animation-duration: 0.5s;
      animation-fill-mode: both;
      animation-delay: $time;
      @if $i%2==0 {
        animation-name: toLeft;
      } @else {
        animation-name: toRight;
      }
    }
  }

css:

// 方向 右-->左
@keyframes toLeft {
  0% {
    opacity: 0;
    transform: translate3d(-30px, 0, 0);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}
// 方向 左-->右
@keyframes toRight {
  0% {
    opacity: 0;
    transform: translate3d(30px, 0, 0);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

效果图:
在这里插入图片描述

  • @while的简单用法:
$types: 4
$type-width: 20px

@while $types > 0
  .while-#{$types}
    width: $type-width + $types
  $types: $types - 1

转化成以下代码

.while-4 {
  width: 24px;
}

.while-3 {
  width: 23px;
}

.while-2 {
  width: 22px;
}

.while-1 {
  width: 21px;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值