美文网首页
vue动画学习

vue动画学习

作者: 五更月下琉璃 | 来源:发表于2019-11-12 17:53 被阅读0次

1基础-淡入淡出

TIM图片20191111153401.png
<transition name="slide-fade">
    <p v-if="show">hello</p>
  </transition>

CSS部分
最基本的用法

.others-enter-active,
  .others-leave-active {
    transition: opacity 1.5s;
  }
  .others-enter,
  .others-leave-to {
    opacity: 0;
  }

可以自定义离开动画。

 .xxx-enter,.xxx-leave-to {
      transform: translateX(18px);
      opacity: 0;
    }

样式上:transition-duration属性

<a v-on:click="show = !show">

    <img :class="{btn:show,btn_copy:!show}" src="/static/bh/btn2.png">

</a>
.btn {

      position: fixed;

      width: 75px;

      left: 10px;

      top: 175px;

      transition-duration: 1.5s;

    }

    .btn_copy {

      position: fixed;

      width: 75px;

      left: -37px;

      top: 175px;

      transition-duration: 1.5s;

    }

动态组件

    <div @click="ChooseA">选A</div>
    <div @click="ChooseB">选B</div>
    <transition name="component-fade" mode="out-in">
      <component v-bind:is="view"></component>
    </transition>
data: {
    view: 'v-a'
  },
 components: {
    'v-a': {
      template: '<div>Component A</div>'
    },
    'v-b': {
      template: '<div>Component B</div>'
    }
  }

乱序插入乱序移除动画

<div id="list-demo" class="demo">
  <button v-on:click="add">Add</button>
  <button v-on:click="remove">Remove</button>
  <transition-group name="list" tag="p">
    <span v-for="item in items" v-bind:key="item" class="list-item">
      {{ item }}
    </span>
  </transition-group>
</div>
data: {
    items: [1,2,3,4,5,6,7,8,9],
    nextNum: 10
  },
  methods: {
    randomIndex: function () {
      return Math.floor(Math.random() * this.items.length)
    },//产生随机数
    add: function () {
      this.items.splice(this.randomIndex(), 0, this.nextNum++)
    },//用splice方法,产生的随机数即是splice的参数,添加一个数,xxx++
    remove: function () {
      this.items.splice(this.randomIndex(), 1)
    },//移除也是同理
  }
.list-item {
  display: inline-block;
  margin-right: 10px;
}
.list-enter-active, .list-leave-active {
  transition: all 1s;
}
.list-enter, .list-leave-to
{
  opacity: 0;
  transform: translateY(30px);
}

乱序动画列

先安装lodash
在页面引入

import _ from "lodash"
<div id="flip-list-demo" class="demo">
      <button v-on:click="shuffle">Shuffle</button>
      <transition-group name="flip-list" tag="ul">
        <li v-for="item in items" v-bind:key="item">{{ item }}</li>
      </transition-group>
    </div>
items: [1, 2, 3, 4, 5, 6, 7, 8, 9],


shuffle () {
      this.items = _.shuffle(this.items);
    }

动画

.flip-list-move {
    transition: transform 1s;
  }

相关文章

  • vue动画学习

    1基础-淡入淡出 CSS部分最基本的用法 可以自定义离开动画。 样式上:transition-duration属性...

  • Vue学习:动画

    动画:使用过度类名实现动画 v-enter这是一个时间点,是进入之前,元素的起始状态,此时还没有开始进入 v-le...

  • Vue中的动画

    Vue动画 Vue动画API 定义不同的名称动画 第三方动画库Animate.css和Vue的结合使用 enter...

  • 前端系统学习 10. Vue高级用法

    Vue 高级用法 动画特效 transition 实现路由切换动画 App.vue Home -> List ->...

  • vue的动画特效

    一、Vue中的CSS动画原理transition标签 二、Vue中的JS动画与velocity.js 三、Vue中...

  • Vue动画

    vue动画 1. vue不能直接实现动画,只提供动画各阶段需要的class 2. 组件提供...

  • vue学习笔记(9):vue动画

    data:{ flag:false, id:'', name:'', list:[ {id:1,name:"赵高"...

  • Vue神一般的打开姿势

    过渡&动画 vue 动画的理解 1)操作 css 的 trasition 或 animation2)vue 会给目...

  • Vue动画

    Vue动画 Vue动画 CSS transition 在进入/离开的过渡中,会有 6 个 class 切换。 对于...

  • 五、Vue动画 ------ 2020-05-07

    1、常见的能触发动画的操作及添加动画的方式 2、Vue动画的基本使用:通过添加CSS样式使用 3、Vue动画的基本...

网友评论

      本文标题:vue动画学习

      本文链接:https://www.haomeiwen.com/subject/tlytictx.html