23.VUE使用动画完成过渡效果


1.使用动画完成过渡效果

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        /*创建*/
        @keyframes myScale {
            from{transform: scale(0)}
            50%{transform: scale(2)}
            to{transform: scale(1)}
        }
        @keyframes myMove{
            0%{
                transform: translateX(0);
            }
            50%{
                transform: translateX(100px);
            }
            100%{
                transform: translateX(200px) translateY(100px);
            }
        }
        .scale-enter-active{
            animation: myScale 2s;
        }
        .scale-leave-active{
            animation: myScale 2s reverse;
        }
        .move-enter-active{
            animation: myMove 2s ;
        }
        .move-enter-active{
            animation: myMove 2s reverse;
        }
    </style>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <button type="button" @click="change=!change">变变变</button>
    <transition name="scale" >
        <h3 v-show="change">放大还是缩小,这是一个问题</h3>
    </transition>
    <transition name="move">
        <h3 v-show="change">移动还是静止,这是一个问题</h3>
    </transition>
</div>

</body>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            change:true,
        },
        methods: {},
    });
</script>
</html>

2.使用第三方动画库来实现过渡效果

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.js"></script>
    <link rel="stylesheet" href="animate.css">
</head>
<body>
<div id="app">
    <button type="button" @click="show=!show">toggle</button>
    <transition enter-active-class="animated bounceInRight" leave-active-class="animated bounceOutLeft">
        <h3 v-if="show">跳跃效果</h3>
    </transition>
    <transition enter-active-class="animated rotateIn" leave-active-class="animated rotateOut">
        <h3 v-if="show">翻转效果</h3>
    </transition>
</div>
</body>
<script>
    /*
    *transition组件上可以更改过渡类名,可以更改的类名如下
    * enter-class
    * enter-active-class
    * enter-to-class
    * 同理:leave
    *
    * transition组件上可以监听的动画钩子函数如下:
    * */
    let vm = new Vue({
        el: "#app",
        data: {
            show:true
        },
        methods: {},
    });
</script>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值