Vue slideToggle不顺畅

问题描述 投票:0回答:1

试图建立一个手风琴菜单。菜单下的项目动画流畅,但菜单关闭和开口不平滑。

我找到了几个像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>
vue.js vuejs2 css-animations slidetoggle
1个回答
0
投票

如果你将margin-bottom更改为-100px,它会变得更加平滑:

.slide-enter,
.slide-leave-to{
opacity: 0;
transform: translateY(-100%);
margin-bottom: -100px;
}
© www.soinside.com 2019 - 2024. All rights reserved.