亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

小程序自定義標題欄寫法(適配各種大小劉海屏)

標簽:
小程序

思路

  • 1.先创建一个自定义组件文件

https://img3.sycdn.imooc.com/60fc2d5f000176e902550196.jpg

  • 2.把基本wxml及wxss文件写好

  • 3.把返回的箭头点击区域弄大点方便点击

  • 4.把标题部分固定宽度,如果超出宽度省略号显示

  • 5.在js里面调用微信提供的apiwx.getMenuButtonBoundingClientRect()获取胶囊大小及位置

  • 6.上一步,得到的位置动态去设置样式,使用style设置样式

  • 7.如果你有页面原生组件建议使用cover-view,但是使用这个标签没有伪类,所有不能使用伪类写箭头样式

  • 8.我这里使用胶囊底部button为整体高度,所有需要加上6px这样会更美观点,不然会贴边

  • 效果图如下及代码部分请继续阅读:

https://img4.sycdn.imooc.com/60fc2d5f0001c4b603760100.jpg

<view class="custom_header" style="height:{{barHeight + 6}}px;">

    <view class="arrow" style="height:{{titleHeight}}px;top:{{top}}px;"></view>

    <view class="custom_header_title" style="height:{{titleHeight}}px;line-height:{{titleHeight}}px;top:{{top}}px;">访客详情</view>

</view>



data: {

    barHeight: 56,

    titleHeight: 32,

    top: 24

},

methods: {

        init() {

            // 右边胶囊大小高度

            let getMenuButton = wx.getMenuButtonBoundingClientRect();

            console.log(getMenuButton, 'getMenuButton')

            this.setData({ barHeight: getMenuButton.bottom,

                            titleHeight: getMenuButton.height,

                            top: getMenuButton.top });

        }

},

lifetimes: {

    // 生命周期函数,可以为函数,或一个在methods段中定义的方法名

    attached: function () {this.init();},

    moved: function () { },

    detached: function () { },

},


.custom_header {

  position: fixed;

  width: 100%;

  top: 0;

  left: 0;

  background-color: #ccc;

  z-index: 10000; }

  .custom_header .arrow {

    position: absolute;

    width: 80rpx;

    height: 64rpx;

    margin-left: 0; }

    .custom_header .arrow::before {

      content: "";

      position: absolute;

      left: 25rpx;

      top: 50%;

      width: 22rpx;

      height: 22rpx;

      border-top: 1px solid #ffffff;

      border-right: 1px solid #ffffff;

      -webkit-transform: translate(0, -50%) rotate(-135deg);

      -moz-transform: translate(0, -50%) rotate(-135deg);

      transform: translate(0, -50%) rotate(-135deg); }

  .custom_header .custom_header_title {

    position: absolute;

    left: 0;

    right: 0;

    margin: auto;

    width: 420rpx;

    font-size: 34rpx;

    color: #FFFFFF;

    text-align: center;

    font-weight: bold;

    text-overflow: ellipsis;

    white-space: nowrap;

    overflow: hidden; }




作者:哈罗哈皮


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
33
獲贊與收藏
208

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消