首页 > 其他分享 >Vue中的过渡效果

Vue中的过渡效果

时间:2022-09-22 10:36:40浏览次数:73  
标签:Vue translateX 效果 transition transform leave 过渡 active hello

文中介绍简单动画  

更多动画 Animate.css 插件

只有一个元素

<div>
        <button @click="isShow=!isShow">显示/隐藏</button>
          <!-- appear 页面加载完成就执行动画 -->
        <transition name="hello" appear>
       <h1 v-show="isShow">你好啊!</h1>
     </transition>
</div>

 

多个元素时

  <div>
        <button @click="isShow=!isShow">显示/隐藏</button>
        <transition-group name="hello" appear>
            <h1 v-show="!isShow" key="1">你好啊!</h1>
            <h1 v-show="isShow" key="2">尚硅谷!</h1>
        </transition-group>
    </div>

css第一种写法

<style scoped>
h1 {
    background: orange;
}
/* transition 没有 name 时 */
 .v-enter-active {
    animation: anim 1s linear;
}
.v-leave-active {
    animation: anim 1s linear reverse;
} 
@keyframes anim {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}
</style>

css第二种写法

<style scoped>
h1 {
    background-color: darksalmon;
}
.hello-enter-active,
.hello-leave-active {
    transition: 1s linear;
}
/* transition 或 transition-group 的 name 为 hello 时*/
/* 进入的起点,离开的终点 */
.hello-enter,
.hello-leave-to {
    transform: translateX(-100%);
}
/* 进入的终点,离开的起点 */
.hello-enter-to,
.hello-leave {
    transform: translateX(0);
}
/* 离开的起点 */
/* .hello-leave {
    transform: translateX(0);
} */
/* 离开的终点 */
/* .hello-leave-to {
    transform: translateX(-100%);
} */
</style>

 

标签:Vue,translateX,效果,transition,transform,leave,过渡,active,hello
From: https://www.cnblogs.com/wwll2020/p/16718273.html

相关文章