美文网首页
vue零基础开发025——Vue中Js动画与velocity.j

vue零基础开发025——Vue中Js动画与velocity.j

作者: 文朝明 | 来源:发表于2019-12-06 16:29 被阅读0次

【Vue中Js动画】

<html>
<head>
    <meta charset="utf-8" />
    <title>Vue中Js动画与velocity.js的结合</title>
    <script src="./vue.js"></script>
    <script src="./velocity.js"></script>
</head>
<body>
    <div id="root">
        <!--钩子函数@before-enter@before-leave@enter@leave@after-enter@after-leave-->
        <transition name="fade"
                    @before-enter="handleBeforeEnter"
                    @enter="handleEnter"
                    @after-enter="handleAfterEnter">
            <div v-if="show">hello world</div>
        </transition>
        <button @click="handleClick">切换</button>
    </div>
    <script>

        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function () {
                    this.show = !this.show
                },
                handleBeforeEnter: function (el) {
                    // console.log('beforeEnter')
                    el.style.color = "red"
                },
                handleEnter: function (el, done) {
                    setTimeout(() => {
                        el.style.color = "green"
                    }, 2000)
                    setTimeout(() => {
                        done()
                    }, 4000)
                },
                handleAfterEnter: function (el) {
                    el.style.color = "#000"
                }
            }
        })

    </script>
</body>
</html>
2s红色
4s绿色
done黑色

【velocity.js】

<html>
<head>
    <meta charset="utf-8" />
    <title>Vue中Js动画与velocity.js的结合</title>
    <script src="./vue.js"></script>
    <script src="./velocity.js"></script>
</head>
<body>
    <div id="root">
        <!--@before-enter@before-leave@enter@leave@after-enter@after-leave-->
        <transition name="fade"
                    @before-enter="handleBeforeEnter"
                    @enter="handleEnter"
                    @after-enter="handleAfterEnter">
            <div v-if="show">hello world</div>
        </transition>
        <button @click="handleClick">切换</button>
    </div>
    <script>

        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function () {
                    this.show = !this.show
                },
                /* handleBeforeEnter: function (el) {
                     // console.log('beforeEnter')
                     el.style.color = "red"
                 },
                 handleEnter: function (el, done) {
                     setTimeout(() => {
                         el.style.color = "green"
                     }, 2000)
                     setTimeout(() => {
                         done()
                     }, 4000)
                 },
                 handleAfterEnter: function (el) {
                     el.style.color = "#000"
                 }*/
                handleBeforeEnter: function (el) {

                    el.style.opacity = 0
                },
                handleEnter: function (el, done) {
                    Velocity(el, {
                        opacity: 1
                    }, {
                        duration: 1000,
                        complete: done
                    })
                },
                handleAfterEnter: function (el) {
                    console.log('动画结束')
                }
            }
        })

    </script>
</body>
</html>
Velocity.js

相关文章

网友评论

      本文标题:vue零基础开发025——Vue中Js动画与velocity.j

      本文链接:https://www.haomeiwen.com/subject/lbeegctx.html