小程序 自定義頂部導航欄,添加背景圖,自定義返回按鈕

https://developers.weixin.qq....

全局配置
window
navigationStyle
導航欄樣式,僅支持如下值:javascript

  • default 默認樣式
  • custom 自定義導航欄,只保留右上角膠囊按鈕
小程序代碼片斷
wechatide://minicode/AMdHRJm27G3I

bg2

設置 navigationStyle
/app.json
{
  "pages": [
    "index/index",
    "index/main",
    "index/second",
    "index/halfPage"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle": "black",
    "navigationStyle": "custom"
  }
}
/index/second.wxml
<!--index/second.wxml-->
<view class="halfPage">
    <image mode="top" src="{{bg}}" class="image"/>
    <view class="arrow" bindtap="goback"></view>
    <view class="home"></view>
</view>
/index/second.wxss
/* index/second.wxss */
.halfPage{
  display: flex;
  width: 100vw;
  height: 100vh;
  background-color: aliceblue;
}

.image{
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  width: 100vw;
  height: 30vh;
  overflow: hidden;
}

.arrow{
  position: fixed;
  left: 40rpx;
  top: 73rpx;
  display: flex;
  width: 35rpx;
  height:35rpx;
  border-left: 4rpx solid #6dc6ff;
  border-top: 4rpx solid #6dc6ff;
  transform: rotate(-45deg);
}
/index/second.js
// index/second.js
Page({

  /**
   * 頁面的初始數據
   */
  data: {
    bg:'/image/bg.jpg'
  },

  goback(){
    wx.navigateBack({delata:1})
  }
})
原文連接 https://github.com/WangShuXia...
相關文章
相關標籤/搜索