当前位置: 首页 > news >正文

小程序UI(自定义Navbar)

组件代码

// app.js
App({onLaunch() {const systemInfo = wx.getSystemInfoSync();this.globalData.statusBarHeight = systemInfo.statusBarHeight;},globalData: {statusBarHeight: 0,}
})

header.wxml

<view class="header custom {{fixedTop?'fixed':''}}" style="padding-top:{{statusBarHeight}}px; background: {{background}}; z-index: 10"><view class="navigation" wx:if="{{nav}}"><navigator class="nav" hoverClass="none" openType="navigateBack" wx:if="{{canGoBack&&autoGoBack}}"><image src="https://nodestatic.fbstatic.cn/wxmini/imgs/back.png"></image></navigator><view bindtap="back" class="nav" wx:if="{{canGoBack&&!autoGoBack}}"><image src="https://nodestatic.fbstatic.cn/wxmini/imgs/back.png"></image></view><text wx:if="{{canGoBack&&!small}}">|</text><navigator class="nav" hoverClass="none" openType="reLaunch" url="../../pages/index/index" wx:if="{{!(small&&canGoBack)}}"><image src="https://nodestatic.fbstatic.cn/wxmini/imgs/home.png"></image></navigator></view><slot></slot><text class="title" style="margin-right: {{small?80:0}}rpx;color:#{{small?'3C464F':'000'}}" wx:if="{{showTitle}}">{{title}}</text>
</view>
<view class="{{!fixedTop?'fixed':''}}" style="height: calc({{statusBarHeight+44}}px)"></view>

CSS

.header {box-sizing: initial;color: #3c464f;font-size: 34rpx;font-weight: 700;height: 44px;line-height: 44px;position: relative;text-align: center
}.navigation {align-items: center;background: #fff;border: 1px solid #ebebeb;border-radius: 28px;bottom: 8px;color: #ebebeb;display: -webkit-flex;display: flex;font-weight: 100;height: 28px;justify-content: center;left: 15rpx;line-height: 0;position: absolute
}.header .navigation text {display: inline;flex: none;font-size: 16px;margin: 0
}.header .navigation image {height: 16px;width: 16px
}.header .nav {height: 16px;width: 38px
}.fixed {left: 0;position: fixed;right: 0;top: 0;z-index: -100
}.header .title {display: inline-block;max-width: 390rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap
}@media screen and (min-width:600px) {.header {font-size: 20px}
}

JS


const app = getApp();Component({options: {},properties: {title: {value: "",type: String},background: {value: "#fff",type: String},nav: {value: true,type: Boolean},fixedTop: {value: true,type: Boolean},small: {value: false,type: Boolean},showTitle: {value: true,type: Boolean},autoGoBack: {value: true,type: Boolean}},data: {statusBarHeight: app.globalData.statusBarHeight,canGoBack: false},attached: function () {this.setData({canGoBack: getCurrentPages().length > 1});},methods: {back: function () {this.triggerEvent("back");}}
});

使用

{"usingComponents": {"header": "../../components/header/header"}
}

index.wxml

<header title="关于我们"></header>

<header title="证件照首页" nav="{{false}}"></header>
<navigator class="about-us" hoverClass="none" style="top: calc({{statusBarHeight+22}}px - 24rpx)" url="../about-us/about-us"><image src="/static/icon-about-us.png"></image>
</navigator>

CSS

.about-us {left: 30rpx;position: fixed;z-index: 10
}.about-us,
.about-us image {height: 48rpx;width: 48rpx
}

http://www.dtcms.com/a/342301.html

相关文章:

  • 【TrOCR】用Transformer和torch库实现TrOCR模型
  • yggjs_rlayout 科技风主题布局使用教程
  • StarRocks不能启动 ,StarRocksFe节点不能启动问题 处理
  • macos使用FFmpeg与SDL解码并播放H.265视频
  • 【TrOCR】模型预训练权重各个文件说明
  • 从800米到2000米:耐达讯自动化Profibus转光纤如何让软启动器效率翻倍?
  • 表达式(CSP-J 2021-Expr)题目详解
  • Django的生命周期
  • 如何在DHTMLX Scheduler中实现带拖拽的任务待办区(Backlog)
  • 非常飘逸的 Qt 菜单控件
  • logger级别及大小
  • 如何安装和配置W3 Total Cache以提升WordPress网站性能
  • C++设计模式--策略模式与观察者模式
  • 小红书AI落地与前端开发技术全解析(From AI)
  • Python 正则表达式(更长的正则表达式示例)
  • 【基础排序】CF - 赌场游戏Playing in a Casino
  • 机器学习4
  • 精算中的提升曲线(Lift Curve)与机器学习中的差别
  • 网络打印机安装操作指南
  • 健康常识查询系统|基于java和小程序的健康常识查询系统设计与实现(源码+数据库+文档)
  • CentOS7安装部署PostgreSQL
  • 《PostgreSQL内核学习:slot_deform_heap_tuple 的分支消除与特化路径优化》
  • ES_文档
  • 2025-08-21 Python进阶6——迭代器生成器与with
  • Python项目开发- 动态设置工作目录与模块搜索路径
  • strerror和perror函数的使用及其联系和区别
  • 43-Python基础语法-3
  • QWidget/QMainWindow与QLayout的布局
  • CSDN使用技巧
  • Pandas中数据分组进阶以及数据透视表