日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

uniapp 填充剩余高度

發(fā)布時(shí)間:2024/9/19 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uniapp 填充剩余高度 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

  • Hbuilder X 2.7.14.20200618 (不清楚uniapp的版本,用工具版本代替)
  • 需求,如下圖:

嘗試 Flex 布局的flex-grow屬性

flex-grow屬性定義項(xiàng)目的放大比例,默認(rèn)為0,即如果存在剩余空間,也不放大。

我以為能夠縱向放大。經(jīng)過(guò)實(shí)驗(yàn)和網(wǎng)上查找,該屬性是橫向放大(計(jì)算剩余寬度,不能計(jì)算剩余高度)。

這個(gè)不行就換一個(gè)。

手工計(jì)算高度

  • 定義高度變量
  • export default {data() {return {newsPanelHeight: 0,}} }
  • 計(jì)算高度
  • export default {data() {return {newsPanelHeight: 0,}},onReady(){var _this = this;uni.getSystemInfo({success: function (res) {_this.newsPanelHeight = res.windowHeight - 200;}});}, }
  • 綁定style
  • <template><view class="content"><!-- 頂部輪播 --><uni-swiper-dot>...</uni-swiper-dot><!-- 滾動(dòng)列表 --><view class="newsScrollContainer" :style="{ height: newsPanelHeight + 'px' }"><scroll-view class="newsScroll" scroll-y="true">...</scroll-view></view></view> </template>

    遇到不固定高度怎么辦?

    export default {data() {return {newsPanelHeight: 0,}},onReady(){var _this = this;uni.getSystemInfo({success: function (res) {uni.createSelectorQuery().select(".newsScrollContainer").boundingClientRect(function(boundRect){_this.newsPanelHeight = res.windowHeight - boundRect.top;}).exec();}});}, }

    說(shuō)明:剩余高度 = 屏幕高度 - 控件".newsScrollContainer"的top值

    參考

    https://www.ruanyifeng.com/blog/2015/07/flex-grammar.html
    https://blog.csdn.net/qq_26766789/article/details/76890311
    https://blog.csdn.net/weixin_39793790/article/details/105397875
    https://uniapp.dcloud.io/use?id=class-%E4%B8%8E-style-%E7%BB%91%E5%AE%9A
    https://uniapp.dcloud.io/api/system/info?id=getsysteminfo

    總結(jié)

    以上是生活随笔為你收集整理的uniapp 填充剩余高度的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。