zoukankan      html  css  js  c++  java
  • 【小程序】自定义顶部导航栏

     
    需求:在小程序非tab页上顶部导航栏上加一个返回按钮
     
    在app.js中
    App({
        onLaunch: function () {
            let that = this;
            wx.getSystemInfo({//获取系统信息
                success: function(res) {
                    that.globalData.statusBarHeight = res.statusBarHeight;//获取状态栏的高度,单位px
                },
            })
        },
        globalData: {
            auntName:'',
            backPath:'',
            pathType:''
        },
    })
    

    在内页面上

    json页面(custom 自定义导航栏,只保留右上角胶囊按钮)

    {
        "navigationStyle":"custom"
    }
    

    wxml页面

    <view class="halfPage" style="padding-top:{{statusBarHeight}}px; height:44px; '100%; background:red" >
        <view bindtap="goback" class="arrowbox" wx:if="{{backPath!=''}}">
            <view class="arrow" ></view>
        </view>
    </view>
    

    wxss页面上

    .halfPage{
         100%;
        background-color: #fff;
        position: fixed;
        top: 0;
        display: flex;
        align-items: center;
        z-index: 9999;
    }
    .halfPage .arrowbox{
        height: 44px;
         max-content;
        display: flex;
        align-items: center;
    }
    .halfPage .arrow{
         20rpx;
        height:20rpx;
        border-left: 4rpx solid #000;
        border-top: 4rpx solid #000;
        transform: rotate(-45deg);
        margin-left: 30rpx;
        margin-right: 20rpx;
    }
    

    js页面中

    const app = getApp()
    Page({
    
    
    /**
    * 页面的初始数据
    */
    data: {
        backPath:'',
        statusBarHeight: getApp().globalData.statusBarHeight,
    },
    goback() {
        app.globalData.pathType = 'order';
        wx.navigateTo({
            url: this.data.backPath,
        })
    },
    onLoad: function (options) {
        if (options.id) {
            this.setData({
                staff_id: options.id
            })
        }
    },
    /**
    * 生命周期函数--监听页面显示
    */
    onShow: function () {
           app.globalData.pathType = '';
            if (app.globalData.backPath!=''){
                this.setData({
                    backPath: app.globalData.backPath
                })
            }else{
                this.setData({
                    backPath: ''
                })
            }
    },
    })
  • 相关阅读:
    Flash、Ajax各自的优缺点,在使用中如何取舍?
    纯CSS气泡框实现方法探究
    CSS里padding和margin的区别是什么?
    img图片标签alt和title属性的区别
    JS中都有哪些数据类型呢?
    剑指offer---按只字形顺序打印二叉树
    剑指offer---序列化二叉树
    剑指offer---二叉树的下一个结点
    剑指offer---二叉树的深度
    剑指offer---平衡二叉树
  • 原文地址:https://www.cnblogs.com/guanpingping/p/12784422.html
Copyright © 2011-2022 走看看