美文网首页
Vue加入购物车的动画效果

Vue加入购物车的动画效果

作者: ___大鱼___ | 来源:发表于2018-11-08 14:47 被阅读11次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .circle{
            border: solid 1px red;
            background-color: red;
            border-radius: 50%;
            width: 50px;
            height: 50px;

        }

    </style>
</head>
<body>
    <div id="app">
        <input type="button" value="点我加入购物车" @click=flag=!flag>


        <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
            <p class="circle" v-show="flag"> </p>
        </transition>






    </div>


    <script>

        var app = new Vue({
            el: '#app',
            data:{
                flag: false
            },
            methods: {
                beforeEnter(el){
                    el.style.transform = "translate(0, 0)"
                },
                enter(el, done){
                    // el.offsetWidth 强制html渲染动画
                    // el.offsetWidth 这句话如何不写就不会有动画效果直接渲染的
                    el.offsetWidth;
                    el.style.transform = "translate(150px, 250px)";
                    el.style.transition = "all 2s ease";
                    console.log(done);
                    done()
                },
                afterEnter(el){
                    this.flag = !this.flag
                },
            },
            created: function () {

            },
            mounted: function () {

            }
        })

    </script>
</body>
</html>

相关文章

网友评论

      本文标题:Vue加入购物车的动画效果

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