温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

在Vue中使用 animate.css 库

发布时间:2020-08-06 01:39:32 来源:网络 阅读:373 作者:梁十八 栏目:web开发

要在class的样式中加上transform-origin: left center,不然可能会出问题:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="./vue.js"></script>
    <!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
    <style type="text/css">
        @keyframes bounce-in {
            0% {
                transform: scale(0);
            }
            50% {
                transform: scale(15);
            }
            100% {
                transform: scale(1);
            }
        }
        .fade-enter-active {
            transform-origin: left center;
            animation: bounce-in 1s;
        }
        .fade-leave-active {
            transform-origin: left center;
            animation: bounce-in 1s reverse;
        }
    </style>
</head>
<body>
    <div id="root">
        //name随便取名:
        <transition name="fade">
            <div v-show="show">hello</div>
        </transition>
        <button @click="handleClick">切换</button>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                }
            }
        });
    </script>
</body>
</html>

当然,还可以自定义style中的class名:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="./vue.js"></script>
    <!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
    <style type="text/css">
        @keyframes bounce-in {
            0% {
                transform: scale(0);
            }
            50% {
                transform: scale(15);
            }
            100% {
                transform: scale(1);
            }
        }
        /*.fade-enter-active {
            transform-origin: left center;
            animation: bounce-in 1s;
        }
        .fade-leave-active {
            transform-origin: left center;
            animation: bounce-in 1s reverse;
        }*/
        .haha-active {
            transform-origin: left center;
            animation: bounce-in 1s;
        }
        .haha-leave {
            transform-origin: left center;
            animation: bounce-in 1s reverse;
        }

    </style>
</head>
<body>
    <div id="root">
        //name随便取名:
        <!-- <transition name="fade">
            <div v-show="show">hello</div>
        </transition> -->
        //自定义class名字:
        <transition name="fade" enter-active-class="haha-active" leave-active-class="haha-leave">
            <div v-show="show">hello</div>
        </transition>
        <button @click="handleClick">切换</button>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                }
            }
        });
    </script>
</body>
</html>

自己命名class名有个好处,可以用别人的动画。css在这个网址下载:https://daneden.github.io/animate.css/

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="./animate.css">
    <script src="./vue.js"></script>
    <!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
</head>
<body>
    <div id="root">
        //name随便取名:
        <!-- <transition name="fade">
            <div v-show="show">hello</div>
        </transition> -->
        //自定义class名字:
        <transition name="fade" enter-active-class="animated rubberBand" leave-active-class="animated hinge">
            <div v-show="show">hello</div>
        </transition>
        <button @click="handleClick">切换</button>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                }
            }
        });
    </script>
</body>
</html>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI