当前位置:网站首页>微信小程序之下拉菜单场景

微信小程序之下拉菜单场景

2022-06-23 13:14:00 qq_45911550

效果图:
在这里插入图片描述
在这里插入图片描述
app.wxss文件

.title{
    
    display:flex;
    flex-direction: row;
    margin:50rpx;
    justify-content: center;
}

js文件

Page({
    
    data:{
    
        li:['默认排序','离我最近','价格最低','价格最高'],
        shownavindex:0
    },
    // 下拉事件
    listmenu: function(e) {
    
        if (this.data.openif) {
    
            this.setData({
    
                openif: false,
                shownavindex: 0
            })
        } else {
    
            this.setData({
    
                content: this.data.li,
                openif: true,
                shownavindex: e.currentTarget.dataset.nav
            })
        }
    }
})

wxml文件

<view class="title">2.下拉菜单场景小案例</view>
<view class="page">
    <!--导航内容-->
    <view class="nav">
        <view class="nav-item {
    {shownavindex == 1? 'active' : ''}}" bindtap="listmenu" data-nav="1">
            <view class="content">排序</view>
            <view class="icon"></view>
        </view>
        <view class="nav-item">
            <view class="content">时间</view>
            <vew class="icon"></vew>
        </view>
        <view class="nav-item">
            <view class="content">价格</view>
            <vew class="icon"></vew>
        </view>
    </view>
    <!--下拉内容-->
    <view class="list {
    {openif ? 'down' : 'up'}} ">
        <view wx:for="{
    {content}}">
            {
    {
    item}}
        </view>
    </view>
</view>

josn文件

{
    
  "usingComponents": {
    }
}

wxss文件

.page{
    
    overflow: hidden;  /*页面溢出隐藏*/
}
.nav{
    
    position: relative;
    z-index: 1;  /*页面元素谁覆盖在谁的上面*/
    display: flex;
    flex-direction: row;
    background: white;
}
.nav-item{
    
    display: flex;
    flex: 1;  /*几个内容等分屏幕*/
    text-align: center;
    height: 90rpx;
    align-items: center;
    justify-content: center;
    font-size: 30rpx;
    border: 1px solid gray;
}
.icon{
    
    border: 10rpx solid transparent;
    border-top: 10rpx solid gray;
    margin-left: 12rpx;
}
.list{
    
    display: none;  /*刚开始尚未显示,所以显示none*/
    width: 100%;
    /*overflow-y: scroll;*/
    padding: 0 0 0 20rpx;
    line-height: 100rpx;
    background: white;
}
.list view{
    
    border-bottom: 1px solid gray;
    font-size: 32rpx;
}
.nav-item.active .content{
      /*注意有空格*/
    color: skyblue;
}
.nav-item.active .icon{
    
    border-bottom: 10rpx solid skyblue;
    border-top: 0;
}
.down{
    
    display: block;
    animation: slidown 0.001s ease-in both;  /*添加动画*/
}
@keyframes slidown{
    
    from{
    
        transform: translateY(-100%);
    }
    to{
    
        transform: translateY(0%);
    }
}
.up{
    
    display: block;
    animation: slidup 0.001s ease-in both;
}
@keyframes slidup{
    
    from{
    
        transform: translateY(0%);
    }
    to{
    
        transform: translateY(-100%);
    }
}
原网站

版权声明
本文为[qq_45911550]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45911550/article/details/120436768