小程序弹出菜单的实现

王嬷嬷
• 阅读 4194

需求

点击标签栏按钮,向下弹出菜单,再次点击,收回菜单

小程序弹出菜单的实现


要解决的问题

  1. 标签栏三栏样式,标签栏固定不动;
  2. 点击标签栏弹出菜单,并且出现透明遮罩;
  3. 遮罩优先级在弹出框之下;
  4. 弹出框内标签的设置;
  5. 滚动栏滚动条的隐藏

如何解决?

  1. 弹性布局,横向,三者平分整栏;
  2. 状态监听点击事件,数据控制hide或者show,通过rgba设置透明度
  3. 弹出框设置z-index;
  4. 弹性布局flex 横向排列 超出后wrap 然后space-around控制间距
  5. ::-webkit-scrollbar {
    width: 0;
    height: 0;
    color: transparent;

}


具体实现

wxml

<import src="../../templates/template" />
<view class="container {{isMask?'mask':''}}">
    <view class="header">
        <view class="filterCity {{status=='1' && isActive?'active':''}}" data-status='1' bindtap="changeStatus">
            <view class="city">城市筛选</view>
            <image src="{{status=='1' && isActive?'../../youzan-image/red-up.png':'../../youzan-image/down.png'}}" />
        </view>
        <view class="filterJob {{status=='2' && isActive?'active':''}}" data-status='2' bindtap="changeStatus">
            <view class="job">职位筛选</view>
            <image src="{{status=='2' && isActive?'../../youzan-image/red-up.png':'../../youzan-image/down.png'}}" />
        </view>
        <view class="filterOrder {{status=='3'&& isActive?'active':''}}" data-status='3' bindtap="changeStatus">
            <view class="order">排序方式</view>
            <image src="{{status=='3' && isActive?'../../youzan-image/red-up.png':'../../youzan-image/down.png'}}" />
        </view>
    </view>
    <block wx:if="{{isActive==true&&status=='1'}}">
        <view class="cityContainer">
            <block wx:for="{{city}}" wx:key="id" wx:for-index="index">
                <view class="city {{isSelect&&index==curIndex?'select':''}}" data-index="{{index}}" bindtap="select">{{item}}</view>
            </block>
        </view>
    </block>
    <block wx:if="{{isActive==true&&status=='2'}}">
        <scroll-view scroll-y="true" class="posContainer">
            <block wx:for="{{cur}}" data-index='index' wx:for-index='index' wx:key="index">
                <view class="title">{{item.title}}</view>
                <view class="poscontent">
                    <view  wx:for="{{item.types}}" wx:for-item="type" wx:key='id' wx:for-index="{{index}}" data-index="{{index}}">
                        <view class="tag {{isSelect&&index==curIndex?'select':''}}" data-id="{{id}}" bindtap="multiSelect">{{type}}</view>
                    </view>
                </view>
            </block>
            <view class="confirm">
                <button class="weui-btn" type="warn">确认</button>
            </view>
        </scroll-view>
    </block>
    <block wx:if="{{isActive==true&&status=='3'}}">
        <view class="orderContainer">
            <view class="block">智能排序</view>
            <view class="block">时间排序</view>
            <view class="block">薪资排序</view>
        </view>
    </block>
    <view class="listContainer"  >
        <view wx:for="{{jobList}}" wx:key="index" data-index="{{index}}">
            <template is="list-item" data="{{...item}}" />
        </view>
    </view>
    <view class="search " bindtap="search">
        <image src="../../youzan-image/search.png" />
        <text>搜索</text>
    </view>

</view>

wxss

page {
    position: relative;
    width: 100%;
    height: 100vh;
}

.header {
    width: 100%;
    height: 80rpx;
    position: fixed;
    top: 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    text-align: center;
    color: #313131;
    font-size: 16px;
    border-bottom: 1rpx solid #eeeeee;
    z-index: 9999;
    background-color: #fff;
}

.filterCity {
    flex: 1;
    position: relative;
    height: 80rpx;
    line-height: 80rpx;
}

.filterJob {
    position: relative;
    flex: 1;
    height: 80rpx;
    line-height: 80rpx;
}

.filterOrder {
    position: relative;
    flex: 1;
    height: 80rpx;
    line-height: 80rpx;
}

.header image {
    position: absolute;
    right: 15rpx;
    top: 26rpx;
    width: 30rpx;
    height: 30rpx;
}

.active {
    color: #ef0001;
}

.mask {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 80rpx;
    background-color: rgba(15, 15, 26, 0.3);
}

.cityContainer {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: space-between;
    flex-wrap: wrap;
    width: 100%;
    height: 300rpx;
    z-index: 999;
    background-color: #fff;
    border-bottom: 1rpx solid #e9e9e9;
    padding-bottom: 130rpx;
}

.cityContainer .city {
    display: block;
    font-size: 15px;
    margin-top: 100rpx;
    width: 150rpx;
    height: 50rpx;
    line-height: 50rpx;
    text-align: center;
    border: 1rpx solid #e9e9e9;
    overflow: hidden;
}

.select {
    color: #ffffff;
    background-color: #ed0000;
}

.posContainer {
    height: 980rpx;
    width: 100%;
    background-color: #fff;
    /* overflow:auto; */
}

::-webkit-scrollbar {
    width: 0;
    height: 0;
    color: transparent;
}

.title {
    margin-top: 55rpx;
    font-size: 15px;
    margin-left: 28rpx;
}

.poscontent {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: -15rpx;
}

.tag {
    margin-left: 28rpx;
    margin-top: 23rpx;
    font-size: 13px;
    width: 150rpx;
    height: 50rpx;
    line-height: 50rpx;
    text-align: center;
    border: 1rpx solid #e9e9e9;
}

.confirm {
    width: 100%;
    height: 150rpx;
    border: 1rpx solid transparent;
    background-color: #fff;
}

.weui-btn {
    position: fixed;
    width: 95%;
    bottom: 52rpx;
    left: 50%;
    transform: translateX(-50%);
}

.orderContainer {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    background-color: #fff;
    width: 100%;
    height: 125rpx;
}

.block {
    font-size: 13px;
    width: 200rpx;
    height: 50rpx;
    line-height: 50rpx;
    text-align: center;
    border: 1rpx solid #e9e9e9;
}

.search {
    position: fixed;
    bottom: 80rpx;
    background-color: #fff;
    right: 25rpx;
    width: 150rpx;
    height: 75rpx;
    line-height: 75rpx;
    text-align: center;
    border-radius: 35rpx;
    box-shadow: 1rpx 1rpx 7rpx 7rpx #f5f5f5;
}

.search image {
    width: 30rpx;
    height: 30rpx;
}

.search text {
    font-size: 15px;
    padding-left: 9rpx;
    color: #666666;
}

.listContainer {
    width: 100%;
    height: 100%;
    margin-top: 80rpx;
}

js


import category from '../../api/employ'
import jobList from '../../api/detail'
Page({
  data: {
    curIndex: '',
    isActive: false,
    jobList:[],
    cur: [],
    job: [],
    isShow: true,
    status: 0,
    isMask: false,
    isSelect: false,
    city: ['全国', '杭州', '北京', '深圳', '上海', '广州', '武汉', '重庆']
  },
  changeStatus(e) {
    let status = e.currentTarget.dataset.status;
    let cur = category;
    this.setData({
      isActive: !this.data.isActive,
      status: status,
      isMask: !this.data.isMask,
      cur: cur,
    })
  },
  select(e) {
    let curIndex = e.currentTarget.dataset.index;
    this.setData({
      isSelect: " curIndex == this.data.curIndex ? '!this.data.isActive' : 'true' ",
      isActive: false,
      isMask:false,
      curIndex: curIndex,
    })
  },
  multiSelect(e){
   let  multiIndex=e.currentTarget.dataset.index;
   this.setData({
     isSelect:!this.data.isSelect,
     curIndex:multiIndex
   })
  },
  search(e) {
    wx.navigateTo({
      url: '../search/search',
    })
  },
  onLoad: function (e) {
    this.setData({
      jobList:jobList
    })
  },
  click:function (e) {
    let id =e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `../detail/detail?id=${id}`,
    })
  }
})
点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
vue+elementui搭建后台管理界面(3侧边栏菜单)
上一节搭好了主框架,但是标签页和侧边栏只是分别展示了各自的菜单,如何将二者联动起来?定义路由规则:当有children属性时,从children里取出path填充到侧边栏,如:{path:'/',redirect:'/dashboard',name:'Container',
雷厉风行 雷厉风行
2年前
Mac效率神器,强大的菜单栏浏览器menubarx for mac 下载
MenubarXforMac是一款功能强大的Mac菜单栏增强软件。它可以使用户根据自己的喜好轻松地调整菜单栏图标,以及为应用程序添加快捷方式和菜单。
仲远 仲远
2年前
Bartender 4 for Mac(菜单栏应用管理软件)
Bartender4forMac是一款菜单栏应用管理软件,能够帮助我们解决系统菜单栏图标越来越多,导致打开某些应用后被隐藏的问题,还你一个干净的Mac菜单栏,Bartender能够让我们把不需要直接显示的菜单栏的应用图标放在这个二级菜单栏中,或者直接隐藏,
阮小五 阮小五
2年前
如何解决“pd虚拟机ID无效“的问题
苹果mac电脑上使用ParallelsDesktop18来安装虚拟机,但是却遇到了“虚拟机ID无效”的报错信息,这种情况要怎么办呢?小编为大家带来了详细的解决方法,一起来看看吧!出现这个问题时,我们先在上方的菜单栏点击图标,选择“控制中心”进入“控制中心”
Wesley13 Wesley13
3年前
DOM元素的自动隐藏
在一些有悬浮元素的场景中,比如点击一个按钮弹出菜单后,点击菜单以外的地方,菜单应该被隐藏起来。隐藏的方式最好是自动隐藏,或至少是组件内的自动隐藏。蒙层比如,一个模态框组件(闭包实现)点击蒙层时,响应蒙层的点击事件,可以在事件处理函数中隐藏整个组件。在Vue和React等框架的组件中,这一点非常容易实现。<divclass"com
流浪剑客 流浪剑客
1年前
专业PDF编辑软件:Acrobat Pro DC 2023 for mac 支持M1
是一款Mac上的菜单栏管理软件,它可以帮助用户轻松整理和管理菜单栏上的图标,使其更加整洁和有序。以下是Bartender的一些主要特点和功能:菜单栏图标隐藏:Bartender允许用户将一些不常用的菜单栏图标隐藏起来,只在需要时展示。通过隐藏冗杂的图标,您
绣鸾 绣鸾
1年前
MenubarX for mac(菜单栏浏览器)
是一款功能强大的Mac菜单栏浏览器。它可以在菜单栏中添加一些WebApp,您可以随时在菜单栏中使用这些Web应用程序。它基于网页,因此不需要为小工具单独安装应用程序。MenubarX将网页添加到菜单栏中,并用作本机应用程序。它将为您打开Web应用程序的新世
布袋罗汉 布袋罗汉
2年前
如何在 Mac 上打开表情符号窗口?
打开表情符号窗口和切换到字符查看器以获取其他符号。Mac菜单栏包含Finder的操作以及您当前使用的应用程序。这使得菜单栏成为记住如何访问表情符号键盘的最简单方法。使用菜单栏,单击「编辑」菜单,选择「表情与符号」,或者使用快捷键CommandContro
绣鸾 绣鸾
1年前
Bartender 4:Mac菜单栏图标管理
是一款菜单栏应用管理软件,能够帮助我们解决系统菜单栏图标越来越多,导致打开某些应用后被隐藏的问题,还你一个干净的Mac菜单栏,Bartender能够让我们把不需要直接显示的菜单栏的应用图标放在这个二级菜单栏中,或者直接隐藏,对于崇尚简洁的Mac用户来说,这
子桓 子桓
1年前
菜单栏图标管理 Bartender5激活安装
新增功能速度现在,可以更好地以闪电般的速度访问菜单栏项目。只需在菜单栏中滑动或滚动、单击菜单栏,或者如果您愿意,只需将鼠标悬停即可立即访问隐藏的菜单栏项目。完全访问权限访问MacBook屏幕上的凹口隐藏的菜单栏项目。当需要创建空间来显示MacBook屏幕凹
绣鸾 绣鸾
1年前
Bartender 5 for mac(菜单栏图标管理软件)
是一款Mac上的菜单栏管理软件,它可以帮助用户轻松整理和管理菜单栏上的图标,使其更加整洁和有序。以下是Bartender的一些主要特点和功能:菜单栏图标隐藏:Bartender允许用户将一些不常用的菜单栏图标隐藏起来,只在需要时展示。通过隐藏冗杂的图标,您