vue使用transition实现Jq的slideTrogger滑动效果

vue通过点击实现如同jquery的slideTrogger展开,折叠的滑动效果 ,如下图

实现代码如下 

template模板里面的代码

<template>
    <div class="menu_left">
        <div
            class="type_box"
            v-for="(item,index) in menuData"
            :key="index"
            @click="selectItem(item,index)"
        >
            <div class="first_type">{{item.type}}</div>
            <transition name="moveing">
                <ul
                    v-show="item.open"
                    class="second_type"
                >
                    <li
                        v-for="subItem in item.typeClass"
                        :key="subItem"
                    >{{subItem}}</li>
                </ul>
            </transition>
        </div>
    </div>
</template>

 script代码

export default {
    data() {
        return {
            menuData: [
                {
                    type: "11111",
                    open: false,
                    typeClass: ["11111-1", "11111-2", "11111-3", "11111-4"],
                },
                {
                    type: "22222",
                    open: false,
                    typeClass: ["22222-1", "22222-2", "22222-3", "22222-4"],
                },
            ],
        }
    },
    methods: {
        selectItem(item, index) {
            this.menuData[index].open = !this.menuData[index].open
        },
    },
}

 css代码(scss)

.menu_left {
            width: 150px;
            height: 100%;
            background-color: #215476;
            .type_box {
                cursor: pointer;
                color: #fff;
                text-align: center;
                .first_type {
                    background-color: green;
                    padding: 5px 0;
                    margin: 5px 5px 0 5px;
                    &:hover {
                        color: orangered;
                        background-color: pink;
                    }
                }

                .moveing {
                    /* 设置过渡,只过渡maxheight */
                    &-leave-active,
                    &-enter-active {
                        transition: max-height 0.6s;
                    }
                    /* 使其动作enter后和leave前,高度为0 */
                    &-leave-to,
                    &-enter {
                        max-height: 0px;
                    }
                    /* 使其enter前和leave后,高度为150px */
                    &-enter-to,
                    &-leave {
                        max-height: 120px;
                    }
                }

                .second_type {
                    background-color: #071e47;
                    margin: 0 5px 5px 5px;
                    overflow: hidden;
                    li {
                        height: 30px;
                        line-height: 30px;
                    }
                }
            }
        }


 

记录一下:使用vue的Transition结合css3学习实现jquery的滑动展开和收起功能。

参考学习

Transition | Vue.js

[Vue][transition]Vue中实现类似JQuery中slideUp slideDown的滑动显示隐藏过渡动画效果_vue slidedown_AI Thabo的博客-CSDN博客

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值