微信小程序之侧边列表菜单(侧边菜单)的实现

侧边菜单栏的实现

你好!

先上图

在这里插入图片描述

思路:

.这个侧边菜单其实很简单,大致就是布局先写好,利用小程序的条件渲染,
在不需要点击的时候将其隐藏,需要展示的时候展示出来就好了

wxml:

<view class="objectView">
  <view class="btnShow" catchtap="show">show列表</view>
</view>

<view class="cehuaDa" wx:if="{{isShowSideslip}}">
  <view class="sideslipMenuItemlist">
    <block wx:for="{{sideslipMenuArr}}">
      <view class="sideslipMenuItem" id="{{index}}" catchtap="itemClick">
        {{item}}
      </view>
    </block>
  </view>
  <view class="sideslipMenu" catchtap="offSideslipMen">
  </view>
</view>

js:

//data
    isShowSideslip: false,
    sideslipMenuArr: ['嘿嘿', '哈哈', '啊啊啊', '通通通', '啪啪啪', '嘿嘿嘿', '哒哒哒']

show: function() {
    this.setData({
      isShowSideslip: true
    })
  },
  offSideslipMen: function(){
    this.setData({
      isShowSideslip: false
    })
  }
  ,
  itemClick: function(e) {
    var tapId = e.currentTarget.id;
    var index = this;
    for (var i = 0; i < index.data.sideslipMenuArr.length;i++){
      if (tapId == i){
        wx.showToast({
          title: index.data.sideslipMenuArr[i],
          icon: 'none',
          image: '',
          duration: 1000,
          mask: true,
          success: function(res) {},
          fail: function(res) {},
          complete: function(res) {},
        })
      }
    }
  }
    

.wxss:

page{
  width:100%;
  height: 100%;
}
.objectView{
  width: 100%;
  height: 100%;
  position: absolute;
}
.btnShow{
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 100vh
}
.cehuaDa {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 10;
}

.sideslipMenu {
  background-color: black;
  opacity: 0.6;
  width: 100%;
  height: 100%;
  position: absolute;
  z-index: 9;
}

.sideslipMenuItemlist {
  width: 200rpx;
  background-color: #454545;
  opacity: 1;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 10;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 30rpx;
}

.sideslipMenuItem {
  flex: 1;
  text-align: center;
  color: #fff;
  font-size: 30rpx;
}

代码:

https://github.com/897589417/sideMenuList

我是入梦,谢谢你的观看我的博客,如果有什么错误,请随时联系我,QQ:897589417

  • 2
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue 微信小程序中,可以使用 wx-swiper 实现横向滑动菜单。 1. 在页面的 .vue 文件中,添加以下代码: ```html <view class="swiper"> <swiper class="swiper-container" indicator-dots="false" autoplay="false" circular="false"> <swiper-item class="swiper-item" wx:for="{{list}}" wx:key="index"> <!-- 每个菜单项的内容 --> <view class="menu-item">{{item}}</view> </swiper-item> </swiper> </view> ``` 2. 在页面的 .vue 文件中,定义列表数据和样式: ```javascript data() { return { list: ['菜单1', '菜单2', '菜单3', '菜单4', '菜单5', '菜单6', '菜单7', '菜单8', '菜单9'], currentIndex: 0 } }, methods: { // 点击菜单项时触发 onItemClick(index) { this.currentIndex = index } } ``` ```css .swiper { height: 60rpx; overflow: hidden; } .swiper-container { height: 100%; } .swiper-item { display: flex; justify-content: center; align-items: center; height: 100%; background-color: #fff; color: #333; } .menu-item { font-size: 28rpx; padding: 10rpx 20rpx; border-bottom: 4rpx solid transparent; } .menu-item.active { border-bottom-color: #007aff; } ``` 3. 在菜单项的 view 标签中添加点击事件,并绑定 onItemClick 方法: ```html <view class="menu-item" :class="{active: currentIndex === index}" @tap="onItemClick(index)">{{item}}</view> ``` 这样就可以实现一个简单的横向滑动菜单了。当用户点击菜单项时,菜单项的样式会变成选中状态。可以根据 currentIndex 属性来判断当前选中的菜单项,从而实现相应的逻辑。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值