微信小程序滑动导航栏+搜索界面

这篇文章展示了如何在微信小程序中创建一个具有滑动导航栏、搜索输入框和下拉选择功能的界面。通过JS、WXML和WCSS代码实现屏幕高度自适应以及事件监听,提供了一个基础的交互式布局示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

微信小程序滑动导航栏、搜索、下拉选择界面

滑动屏幕可随着菜单栏切换内容,demo界面,如需更多功能,请根据需求自行完善。
导航栏+搜索界面
1、js代码:

Page({

  /**
   * 页面的初始数据
   */
  data: {
    viewHeight: 640, // 屏幕高度
    index:0,
    array: ['男性', '女性', '未知'],
    tabList: ['测试一','测试二','测试三','测试四','测试五'],
    current: 0
  },
  // tab栏监听
  tabClick(e) {
    var obj = e.currentTarget.dataset;
    this.setData({
      current: obj.index,
      applyState: obj.tag
    })
  },
  // seiper滑动监听
  swiperClick: function (e) {
    this.setData({
      current: e.detail.current
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // 获取手机屏幕高度
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          viewHeight: res.windowHeight
        });
      }
    });
  },
})

2、wxml代码

<view class="bg-color"></view>
<view class="big-box" style="height: {{viewHeight*0.99}}px;">
    <!-- 顶部固定部分 -->
    <view class="tab-fixed">
        <view class="level">
            <picker class="level left-data" bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
                <text>{{array[index]}}</text>
                <text class="angle"></text>
            </picker>
            <view class="level right-data">
                <icon type="search" size="12" color="gray"></icon>
                <input class="search-input" placeholder="请输入关键字" />
                <text class="search-text">搜索</text>
            </view>
        </view>
        <view class="level tab-list">
            <block wx:for="{{tabList}}" wx:for-index="index" wx:for-item="item" wx:key="item">
                <view class="tab-col" bindtap="tabClick" data-index="{{index}}">
                    <view class="tab-title {{current==index?'active-yes':''}}">
                        <text>{{item}}</text>
                    </view>
                </view>
            </block>
        </view>
    </view>
    <!-- 数据列表部分 -->
    <view class="list-data">
        <swiper current="{{current}}" circular="true" bindchange="swiperClick" style="height:{{viewHeight*0.84}}px">
            <block wx:for="{{5}}" wx:for-index="bigIndex" wx:for-item="bigItem" wx:key="bigItem">
                <swiper-item>
                    <scroll-view scroll-y="true" style="height: {{viewHeight*0.84}}px;">
                        <view class="not-data">分享微信小程序demo,进我主页,查看更多哟!</view>
                    </scroll-view>
                </swiper-item>
            </block>
        </swiper>
    </view>
</view>

3、wcss代码

page {
    background-color: #f1f1f1;
}

.bg-color {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 0;
    height: 200rpx;
    background-color: #44ADFB;
    border-bottom-left-radius: 100rpx;
    border-bottom-right-radius: 100rpx;
}

.big-box {
    position: relative;
    z-index: 1;
    background-color: white;
    margin: 0 20rpx;
    border-bottom-left-radius: 15rpx;
    border-radius: 15rpx;
}

.level {
    display: flex;
    flex-direction: row;
    align-items: center;
    font-size: 30rpx;
}

.tab-fixed {
    position: fixed;
    top: 0;
    left: 20rpx;
    right: 20rpx;
    z-index: 5;
    background-color: white;
    border-top-left-radius: 15rpx;
    border-top-right-radius: 15rpx;
}

.angle {
    padding-left: 5rpx;
}

.left-data {
    width: 20%;
    justify-content: center;
    background-color: #e8e8e8;
    margin: 10rpx 10rpx 10rpx 15rpx;
    padding: 10rpx;
    border-radius: 5rpx;
    color: rgb(92, 91, 91);
}

.right-data {
    width: 80%;
    padding: 10rpx 5rpx 10rpx 15rpx;
    background-color: #e8e8e8;
    margin: 10rpx 15rpx 10rpx 0;
    border-radius: 50rpx;
}

.search-input {
    width: 78%;
    padding-left: 10rpx;
}

.search-text {
    width: 22%;
    text-align: center;
    border-left: 1rpx solid white;
    color: #44ADFB;
}

.tab-list {
    justify-content: space-around;
    margin: 0 5rpx;
    padding-top: 12rpx;
    border-bottom: 5rpx solid #f1f1f1;
}

.tab-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tab-title {
    font-size: 30rpx;
    padding-bottom: 12rpx;
    border-bottom: 5rpx solid transparent;
    color: #606266;
}

.active-yes {
    color: #44ADFB;
    border-bottom: 5rpx solid #44ADFB;
}

.list-data {
    padding-top: 170rpx;
}

.not-data {
    font-size: 30rpx;
    padding: 20%;
    text-align: center;
    color: gray;
}

4、json代码

{
  "usingComponents": {},
  "navigationBarTitleText":"导航+搜索",
  "navigationBarBackgroundColor": "#44ADFB"
}

更多demo请进入我的主页查看!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蒜鸟小窝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值