Vue 过渡动画 单个元素与多个元素过渡 集成第三方过渡动画

 

Vue 过渡动画 单个元素与多个元素过渡 集成第三方过渡动画

单个元素过渡

<template>
  <div class="header">
    <button @click="toggle">显示/隐藏</button>
    <transition name="island" appear>
      <div v-show="isShow"  class="line"  >我来了</div>
    </transition>
  </div>
</template>

<script>
export default {
  props: ["addTodo"],
  data: () => ({ isShow: true }),
  methods:{
    toggle(){
      this.isShow = !this.isShow
    }
  }
};
</script>

<style scoped>
.line {
  width: 400px;
  height: 50px;
  background: rgb(224, 224, 65);
  font-size: 20px;
  line-height: 50px;
  margin-top: 20px;
}
/* 进入过程中激活 */
.island-enter-active{
  animation: island 0.5s linear;
}
/* 离开过程中激活 */
.island-leave-active{
  animation: island 1s linear reverse;
}

@keyframes island {
  from{
    transform: translateX(-100%);
  }
  to{
    transform: translateX(0);
  }
}
</style>

<template>
  <div class="header">
    <button @click="toggle">显示/隐藏</button>
    <transition name="island" appear>
      <div v-show="isShow" class="line">我来了</div>
    </transition>
  </div>
</template>

<script>
export default {
  props: ["addTodo"],
  data: () => ({ isShow: true }),
  methods: {
    toggle() {
      this.isShow = !this.isShow;
    },
  },
};
</script>

<style scoped>
.line {
  width: 400px;
  height: 50px;
  background: rgb(224, 224, 65);
  font-size: 20px;
  line-height: 50px;
  margin-top: 20px;
}


/* 进入的起点,离开的终点*/
.island-enter,
.island-leave-to {
  transform: translateX(-100%);
}


/* 进入、离开激活时添加动画 */
.island-enter-active,.island-leave-active{
  transition: 0.5s linear;
}

/* 进入的终点,离开的起点 */
.island-enter-to,
.island-leave{
  transform: translateX(0);
}


</style>

多个元素过渡

transition-group

<template>
  <div class="header">
    <button @click="toggle">显示/隐藏</button>
    <transition-group name="island" appear>
      <div v-show="isShow" class="line" :key="1">我来了</div>
      <div v-show="isShow" class="line" :key="2">我来了2</div>
    </transition-group>
  </div>
</template>

<script>
export default {
  props: ["addTodo"],
  data: () => ({ isShow: true }),
  methods: {
    toggle() {
      this.isShow = !this.isShow;
    },
  },
};
</script>

<style scoped>
.line {
  width: 400px;
  height: 50px;
  background: rgb(224, 224, 65);
  font-size: 20px;
  line-height: 50px;
  margin-top: 20px;
}


/* 进入的起点,离开的终点*/
.island-enter,
.island-leave-to {
  transform: translateX(-100%);
}


/* 进入、离开激活时添加动画 */
.island-enter-active,.island-leave-active{
  transition: 0.5s linear;
}

/* 进入的终点,离开的起点 */
.island-enter-to,
.island-leave{
  transform: translateX(0);
}


</style>

集成第三方库animate.css

npm i animate.css
import 'animate.css'

<template>
  <div class="header">
    <button @click="toggle">显示/隐藏</button>
    <transition
     appear
     name="animate__animated animate__bounce"
     enter-active-class="animate__backInDown"
     leave-active-class="animate__backOutRight"
    >
      <div v-show="isShow" class="line">我来了</div>
    </transition>
  </div>
</template>

<script>
import "animate.css";
export default {
  props: ["addTodo"],
  data: () => ({ isShow: true }),
  methods: {
    toggle() {
      this.isShow = !this.isShow;
    },
  },
};
</script>

<style scoped>
.line {
  width: 400px;
  height: 50px;
  background: rgb(224, 224, 65);
  font-size: 20px;
  line-height: 50px;
  margin-top: 20px;
}
</style>
posted @   IslandZzzz  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2020-02-12 创建Ajax兼容
2019-02-12 保存客户&分页查询&Spring解决延迟加载问题
点击右上角即可分享
微信分享提示