vue 过渡动画 使用

40 篇文章 0 订阅
<template>
    <div>
        <button @click="play('topToTop')">从顶部滑入、顶部滑出</button>
        <button @click="play('topToBottom')">从顶部滑入、底部滑出</button>
        <button @click="play('bottomToTop')">从底部滑入、顶部滑出</button>
        <button @click="play('bottomToBottom')">从底部滑入、底部滑出</button>
        <button @click="play('leftToRight')">从左侧滑入、右侧滑出</button>
        <button @click="play('leftToLeft')">从左侧滑入、左侧滑出</button>
        <button @click="play('rightToLeft')">从右侧滑入、左侧滑出</button>
        <button @click="play('rightToRight')">从右侧滑入、左侧滑出</button>
        <div class="view">
            <transition :name="transName">
                <div v-show="show" class="block">Element</div>
            </transition>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                transName: '',
                show: true,
            }
        },
        methods: {
            play(name) {
                this.transName = name;
                this.show = !this.show;
            }
        }
    }
</script>
<style>
    .view {
        position: relative;
        height: 300px;
        width: 300px;
        background: gainsboro;
        overflow: hidden;
    }
 
    .block {
        position: absolute;
        height: 100%;
        width: 100%;
        text-align: center;
        color: white;
        line-height: 300px;
        background: red;
    }
 
    /*滑入——从顶部*/
    @keyframes slideIn_top {
        0% {
            top: -100%;
        }
 
        100% {
            top: 0;
        }
    }
 
    /*滑入——从底部*/
    @keyframes slideIn_bottom {
        0% {
            top: 100%;
        }
 
        100% {
            top: 0;
        }
    }
 
    /*滑入——从左侧*/
    @keyframes slideIn_left {
        0% {
            left: -100%;
        }
 
        100% {
            left: 0;
        }
    }
 
    /*滑入——从右侧*/
    @keyframes slideIn_right {
        0% {
            left: 100%;
        }
 
        100% {
            left: 0;
        }
    }
 
    /*滑出——从顶部*/
    @keyframes slideOut_top {
        0% {
            top: 0;
        }
 
        100% {
            top: -100%
        }
    }
 
    /*滑出——从底部*/
    @keyframes slideOut_bottom {
        0% {
            top: 0;
        }
 
        100% {
            top: 100%
        }
    }
 
    /*滑出——从左侧*/
    @keyframes slideOut_left {
        0% {
            left: 0;
        }
 
        100% {
            left: -100%
        }
    }
 
    /*滑出——从右侧*/
    @keyframes slideOut_right {
        0% {
            left: 0;
        }
 
        100% {
            left: 100%
        }
    }
 
    
    /*(滑入)——从顶部滑入,从顶部滑出*/
    .topToTop-enter-active {
        animation: slideIn_top 1s;
    }
    /*(滑出)——从顶部滑入,从顶部滑出*/
    .topToTop-leave-active {
        animation: slideOut_top 1s;
    }
 
 
    /*(滑入)——从顶部滑入,从底部滑出*/
    .topToBottom-enter-active {
        animation: slideIn_top 1s;
    }
    /*(滑出)——从顶部滑入,从底部滑出*/
    .topToBottom-leave-active {
        animation: slideOut_bottom 1s;
    }
 
 
    /*(滑入)——从底部滑入,从顶部滑出*/
    .bottomToTop-enter-active {
        animation: slideIn_bottom 1s;
    }
    /*(滑出)——从底部滑入,从顶部滑出*/
    .bottomToTop-leave-active {
        animation: slideOut_top 1s;
    }
 
 
    /*(滑入)——从底部滑入,从底部滑出*/
    .bottomToBottom-enter-active {
        animation: slideIn_bottom 1s;
    }
    /*(滑出)——从底部滑入,从底部滑出*/
    .bottomToBottom-leave-active {
        animation: slideOut_bottom 1s;
    }
 
 
    /*(滑入)——从左侧滑入,从右侧滑出*/
    .leftToRight-enter-active {
        animation: slideIn_left 1s;
    }
    /*(滑出)——从左侧滑入,从右侧滑出*/
    .leftToRight-leave-active {
        animation: slideOut_right 1s;
    }
 
 
    /*(滑入)——从左侧滑入,从左侧滑出*/
    .leftToLeft-enter-active {
        animation: slideIn_left 1s;
    }
    /*(滑出)——从左侧滑入,从左侧滑出*/
    .leftToLeft-leave-active {
        animation: slideOut_left 1s;
    }
 
 
    /*(滑入)——从右侧滑入,从左侧滑出*/
    .rightToLeft-enter-active {
        animation: slideIn_right 1s;
    }
    /*(滑出)——从右侧滑入,从左侧滑出*/
    .rightToLeft-leave-active {
        animation: slideOut_left 1s;
    }
 
 
    /*(滑入)——从右侧滑入,从右侧滑出*/
    .rightToRight-enter-active {
        animation: slideIn_right 1s;
    }
    /*(滑出)——从右侧滑入,从右侧滑出*/
    .rightToRight-leave-active {
        animation: slideOut_right 1s;
    }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呱嗨喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值