网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

你還在發(fā)愁小程序自定義導(dǎo)航欄嗎?

發(fā)布時(shí)間:2018-08-29 09:06 所屬欄目:小程序開(kāi)發(fā)教程

先說(shuō)一下我的需求吧,因?yàn)槲覀兊男〕绦蚴乔短琢藈ebview。 點(diǎn)擊webview里面的項(xiàng)目,點(diǎn)的層級(jí)太深,用戶(hù)后退很麻煩。然后pm又找了一個(gè)自定義的導(dǎo)航的小程序,發(fā)現(xiàn)別人可以,然后我就開(kāi)始研究。

小程序自定義導(dǎo)航欄開(kāi)發(fā)注意點(diǎn)與參考文檔

  • 微信官方設(shè)計(jì)指導(dǎo)中關(guān)于膠囊按鈕的描述 由此推測(cè)膠囊寬度87pt=116px,設(shè)置之后,的確能產(chǎn)生較好的兼容性效果
  • [2018-07-06]根據(jù)測(cè)試截圖發(fā)現(xiàn)微信膠囊寬度應(yīng)該在96px左右,還有待研究
  • 社區(qū)相關(guān)Q&A:自定義標(biāo)題欄高度計(jì)算
  • 使用時(shí)注意方法與屬性版本兼容性
  • 完善之路:
  1. 開(kāi)一個(gè)項(xiàng)目采集設(shè)備的screenHeight,windowHeight,pixelRatio等信息到一個(gè)數(shù)據(jù)庫(kù)中
  2. 微信提供這樣一個(gè)數(shù)據(jù)庫(kù)便于計(jì)算,或者微信優(yōu)化自定義標(biāo)題欄(譬如通知欄可以改變顏色但不要算在自定義范圍內(nèi),給出膠囊寬高到通知欄距離到右側(cè)屏幕邊框距離等相關(guān)參數(shù))

非自定義導(dǎo)航欄高度怎么計(jì)算?

  1. wx.getSystemInfo 和 wx.getSystemInfoSync 獲取機(jī)器信息
  2. screenHeight - windowHeight 計(jì)算標(biāo)題欄高度
  3. 標(biāo)題欄高度
  • 'iPhone': 64,
  • 'iPhone X': 88,
  • 'android': 68

—— 不完全統(tǒng)計(jì)(ip6 , ip5 , ip6p , ipx , 小米mix2 , 小米5等綜合了開(kāi)發(fā)工具提供的數(shù)據(jù)和真機(jī)數(shù)據(jù))所得

有了這些從網(wǎng)上找到的資料,還有名叫貓圈的小程序的例子。開(kāi)始代碼實(shí)現(xiàn)了。

配置

"window": {        
        "navigationBarBackgroundColor": "#fff",        
        "navigationBarTextStyle": "black",       
        "backgroundColor": "#fff",        
        "navigationStyle": "custom"    
    },復(fù)制代碼

這里navigationStyle 配置修改之后就只剩一個(gè)膠囊按鈕,也就意味著所有頁(yè)面的導(dǎo)航都的自定義實(shí)現(xiàn),你可以選擇模版或者組件來(lái)開(kāi)發(fā),這里我是選擇用的組件開(kāi)發(fā)。

然后定義導(dǎo)航的各個(gè)數(shù)值,我是在app。js 里面定義的

title_height: "64",        
        statusbarHeight: "24",        
        titleIcon_height: "32",        
        titleIcon_width: "87",        
        title_top: "24",        
        title_text: "xxx", // iphone X + 24        
        prefix: 24
復(fù)制代碼

組件

wxml的代碼

<view>  
    <view class="title" style="height:{{title_height}}px;padding-top:{{statusbarHeight}}px;background-color:{{isIndex?'#175dc6':'#fff'}}">   
    <view class="title_text" style="color:{{isIndex?'#fff':'#000'}}">{{title_text}}</view>    
        <view wx:if="{{isShow}}" class="title_icon" style="top:{{title_top}}px;height:{{titleIcon_height}}px;width:{{titleIcon_width}}px;background-color:{{isIndex?'#175dc6':'#fff'}}">      
            <image bindtap="_goBack" class="floatL" src="/img/fanhui_icon.png"></image>      
            <view class="floatL"></view>      
            <image bindtap="_goHome" src="/img/home_icon.png"></image>    
        </view>  
    </view>  
    <view style='height:{{title_height}}px;'></view>
</view>復(fù)制代碼

wxss的代碼

.title {  width: 100%;  background-color: #175dc6;  box-sizing: border-box;  position: fixed;  transform: translateZ(0);  z-index: 999990;}
.title_text {  text-align: center;  font-size: 37rpx;  color: #fff;  line-height: 44px;}
.title_icon {  background-color: #175dc6;  position: fixed;  top: 54rpx;  left: 16rpx;  border-radius: 64rpx;  box-sizing: border-box;  border: 0.5px solid #ebe48e;  display: flex;}
.title_icon image {  height: 20px;  width: 20px;  padding-top: 5px;  display: inline-block;  overflow: hidden;}
.title_icon view {  height: 18px;  border-left: 1px solid #bfb973;  margin-top: 6px;}
.floatL {  float: left;}
.title_icon image:nth-of-type(1), .title_icon image:nth-of-type(2) {  padding-right: 10px;  padding-bottom: 10px;  padding-left: 10px;}復(fù)制代碼

js的代碼

const app = getApp();
Component({    
    properties: {        
        isShow: { // 是否顯示后退按鈕            
            type: String,            
            value: "1"        
        },        
        isIndex: { // 是否主頁(yè)            
            type: Boolean,            
            value: false,        
        },        
        title_height: { //             
            type: String,            
            value: app.config.title_height,        
        },        
        titleIcon_height: {            
            type: String,            
            value: app.config.titleIcon_height,        
        },        
        titleIcon_width: {            
            type: String,            
            value: app.config.titleIcon_width,        
        },        
        statusbarHeight: {            
            type: String,            
            value: app.config.statusbarHeight,        
        },        
        title_top: {            
            type: String,            
            value: app.config.title_top,        
        },        
        title_text: {            
            type: String,            
            value: app.config.title_text,        
        },    
    },    
    methods: {        
        _goBack: function() {            
            wx.navigateBack({                
                delta: 1            
            });       
        },        
        _goHome: function() {            
            wx.switchTab({               
                url: "/pages/index/index"            
            });        
            }    
        }
})復(fù)制代碼

這樣組件就寫(xiě)好了  只需要在你每個(gè)頁(yè)面里面用這個(gè)組件傳不同的值就可以了。

應(yīng)用

<header isIndex="true" title_text="首頁(yè)" isShow=""></header> 在首頁(yè)的wxml應(yīng)用。
json 文件里面的配置  
        "navigationBarTitleText": "啦啦啦",  
        "navigationBarBackgroundColor": "#175dc6",  
        "usingComponents": {    
                "header": "/components/layout/header/header"  
        }復(fù)制代碼

效果如圖

適配上可能會(huì)有點(diǎn)問(wèn)題,希望大神有更好的解決方案,告訴我喲。

一步步記錄自己的踩坑歷程~我要做到我技術(shù)不是最好的,但我給你總結(jié)的小程序的東西是最簡(jiǎn)單粗暴的哈哈哈


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24740.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢(xún):800182392 點(diǎn)擊咨詢(xún)
QQ在線咨詢(xún)
AI智能客服 ×