Vue基础-动画/过度

动画

1、创建动画
默认值是v-enter-activev-leave-active

.v-enter-active {
  animation: animate 1s;
}

.v-leave-active {
  animation: animate 1s reverse;
}

@keyframes animate {
  from {
    transform: translateX(-100px);
  }

  to {
    transform: translateX(0px);
  }
}

2、创建标签执行动画
执行动画的标签用transition标签包裹,transition 标签设置了name="hello",对应的v-enter-activev-leave-active要修改为hello-enter-activehello-leave-active;
:appear="true"可以简写为appear

<button @click="isShow = !isShow">显示/隐藏</button>
<transition name="hello" :appear="true">
   <h1 v-show="isShow">你好啊</h1>
</transition>

过度

标签设置与动画一样,参考上面代码
1、设置过度时间

.hello-enter-active,.hello-leave-active {
  transition: 0.5s linear;
}

2、开始起点和结束终点

.hello-enter,.hello-leave-to {
  transform: translateX(-100%);
}

3、开始终点和结束起点

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

多个元素过度
使用transition-group

<transition-group name="hello" :appear="true">
<h1 v-show="isShow" key="1">你好啊</h1>
<h1 v-show="isShow" key="2">你好啊</h1>
</transition-group>

集成第三方动画

1、安装

yarn add animate.css

2、打开第三方动画网址:https://animate.style/,有诸多效果用法

<transition-group appear name="animate__animated animate__bounce" enter-active-class="animate__swing"
   leave-active-class="animate__backOutUp">
   <h1 v-show="isShow" key="3">你好啊</h1>
</transition-group>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容