在Vue中同时使用过渡和动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>在Vue中同时使用过渡和动画</title>
    <script src="./vue.js"></script>
    <link rel="stylesheet" type="text/css" href="./animate.css">
    <style>
        .fade-enter,
        .fade-leave-to{
            opacity: 0;
        }
        .fade-enter.active,
        .fade-leave-active{
            transition:opacity 1s;
        }
    </style>
</head>
<body>
<div id="root">
    <!--执行动画时间已transition时长为准-->
    <!--type = 'transition'-->
    <transition
        :duration="{enter:5000,leave:10000}"
        name="fade"
        appear
        enter-active-class="animated swing fade-enter-active"
        leave-active-class="animated shake fade-leave-active"
        appear-active-class="animated swing"> <!--appear-active-class目的让页面刚渲染就有动画效果-->
        <div v-show="show">hello world</div>
    </transition>
    <button @click="handleClick">toggle</button>
</div>
<script>

    var vm = new Vue({
        el: '#root',
        data: {
            show: true
        },
        methods: {
            handleClick: function () {
                this.show = !this.show
            }
        }
    })
</script>
</body>
</html>

 

posted @ 2018-11-26 14:43  alexbiu  阅读(381)  评论(0编辑  收藏  举报