Vue slideToggle不流畅

时间:2019-02-12 11:59:08

标签: vue.js vuejs2 css-animations slidetoggle

尝试构建手风琴菜单。菜单下项目的动画是平滑的,但是菜单的关闭和打开都不平滑。

我发现了几个类似https://codepen.io/anon/pen/dgBWjy?editors=0100的示例。但还不能解决我的问题

到目前为止,这是我的代码。关于如何解决该问题的任何想法吗?

<template>
<div class="accord">
    <div v-for="group in groups">
        <a class="menu_grps" v-on:click="group.open = !group.open" v-text="group.name"></a>
        <div id="anim">
        <transition name="slide">
        <div v-show="!group.open">
            <div v-for="item in group.items" v-text="item"></div>
        </div>
        </transition>
        </div>
    </div>
</div>
</template>


<script>
export default {
data() {
    return {
        groups: {
            "group 1": {
                name: "Menu 1",
                open: "false",
                items: ['item1', 'item2']
            },
            "group 2": {
                name: "Menu 2",
                open: "false",
                items: ['item1', 'item2', 'item3']
            },
            "group 3": {
                name: "Menu 3",
                open: "false",
                items: ['item1', 'item2', 'item3', 'item4']
            }
        }
    }
}
}
</script>

<style>

.slide-leave-active,
.slide-enter-active {
transition: all .5s ease;
}
.slide-enter,
.slide-leave-to{
opacity: 0;
transform: translateY(-100%);
margin-bottom: -10px;
}
.menu_grps{
background-color: #BFAEAB;
font-size: 18px;
}
#anim {
overflow: hidden;
}
.accord{
display: flex;
flex-direction: column;
}

</style>

1 个答案:

答案 0 :(得分:0)

如果将下边距更改为下面的-100px,它将变得更加平滑:

.slide-enter,
.slide-leave-to{
opacity: 0;
transform: translateY(-100%);
margin-bottom: -100px;
}