微信小程序,左上角返回首頁小房子


github: https://blog.csdn.net/Chen_ITO/article/details/83651917

 

 

需求:

微信小程序分享出去的頁面,需要左上角加上小房子,點擊回到主頁;

這里就需要涉及到自定義頭部

效果圖:

代碼:

PS: 代碼直接復制到wxml和wxss里面即可

1、在test.json中加入

 

{
"navigationStyle": "custom"
}

 


這個就是全屏的意思

2、在test.xml中加入

 

 
  <view class="inaver _30f2b4d" style="background:{{background}};color:{{getColor}}">
    <view class="left _30f2b4d" catchtap="goBack">
      <image class="icon _30f2b4d" src="/images/ic_home_normal.png"/>
    </view>
    <view class="center _30f2b4d">
      <!-- 自定義區域 -->
      
      
    </view>
    <view class="right _30f2b4d">
      <!-- 保護右上角膠囊不被污染 -->
    </view>
  </view>
  <view  class="protect-inaver _30f2b4d">
    <!-- 占據頂部位置, 偽padding板塊 -->
  </view>

ic_home.png自己加自己的

3、在test.wxss中加入

.inaver._30f2b4d {
  box-sizing: border-box;
  padding-top: 44rpx;
  width: 100vw;
  height: 160rpx;
  display: flex;
  position: fixed;
  z-index: 5000;
  top: 0;
  left: 0;
}
 
.inaver .left._30f2b4d {
  width: 100rpx;
  height: 100rpx;
  margin: 8rpx;
}
 
.inaver .left image.icon._30f2b4d {
  width: 60rpx;
  height: 60rpx;
  padding: 10rpx;
  margin: 10rpx;
}
 
.inaver .center._30f2b4d {
  height: 100rpx;
  line-height: 100rpx;
  flex: 1;
  margin: 8rpx;
}
 
.inaver .right._30f2b4d {
  width: 240rpx;
  height: 100rpx;
  margin: 8rpx;
}
 
.protect-inaver._30f2b4d {
  box-sizing: border-box;
  width: 100vw;
  height: 160rpx;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM