Skip to content

FloatingPanel 懸浮面板 ​

懸浮面板元件:fixed 底部面板,頭部拖曳跟手、鬆手吸附到最近錨點。 錨點幾何(百分比換算 / 最近錨點 / 吸附判定 / 拖曳鉗制)全部消費 @lh-ui/share/core/floating-panel 純函式;視口高度經 @/adapter/platform 取(H5 innerHeight / 小程序 windowHeight),元件層零 uni API。 服務篩選、詳情承載、底部操作等場景。

平台差異(登記):視口高度取端側適配(getLhWindowInfo: H5 走 window.innerHeight,小程序走 uni.getWindowInfo().windowHeight); 拖曳統一為 touch 事件(H5 與 MP 一致,touches[0].clientY 取座標); 面板 fixed 定位落在根節點(share styles/floating-panel 的淨化產物), 高度由內聯 style 承載,拖曳中疊加 --dragging 修飾關閉過渡實現跟手。

基礎用法 ​

預設錨點 [60, '40%'](60px 與視口高度的 40% 兩檔):

vue
<template>
  <lh-floating-panel>
    <view>面板內容</view>
  </lh-floating-panel>
</template>

自訂錨點 ​

anchors 為高度陣列:數值 = px,字串 '40%' = 視口高度百分比; 拖曳鬆手後吸附到最近錨點:

vue
<lh-floating-panel :anchors="[120, 320, 560]" @change="onChange" />

受控檔位(v-model) ​

modelValue 傳值即受控:外部推進檔位,面板高度同步;拖曳鬆手派發 update:modelValue / change:

vue
<lh-floating-panel v-model="index" :anchors="[80, 400]" />

僅頭部可拖曳 ​

contentDraggable(預設 true)為 false 時只有頭部把手區響應拖曳, 內容區(如捲動列表)不再接管拖曳:

vue
<lh-floating-panel :content-draggable="false" :anchors="[100, 300]">
  <scroll-view scroll-y>長內容捲動</scroll-view>
</lh-floating-panel>

禁用與安全區 ​

vue
<lh-floating-panel disabled :anchors="[100, 300]" />
<lh-floating-panel :safe-area-inset-bottom="false" :anchors="[100, 300]" />

自訂頭部 ​

header 插槽替換預設把手(插槽內容仍是拖曳區):

vue
<lh-floating-panel :anchors="[100, 300]">
  <template #header>
    <view>自訂頭部</view>
  </template>
</lh-floating-panel>

Props ​

屬性說明類型預設值
anchors吸附高度陣列(數值 px 或 '百分比' 字串)`(numberstring)[]`
modelValue目前吸附檔位下標(受控)number—
contentDraggable內容區可拖曳booleantrue
safeAreaInsetBottom底部安全區留白booleantrue
disabled禁用拖曳booleanfalse
customClass自訂類名(透傳到根節點)string—
sxsx 快速佈局屬性LhSxProps—

Events ​

事件說明回呼參數
update:modelValue檔位變化(受控同步)(index: number)
change鬆手吸附後檔位變化(index: number)
heightChange面板高度變化(拖曳跟手 + 吸附)(height: number)

Slots ​

插槽說明
header頭部拖曳區(預設渲染 __handle 把手)
default面板內容

無障礙 ​

根節點攜帶 role="region" 語意,aria-label 由 share core 的 getFloatingPanelAria 產生(預設「懸浮面板 第 i / N 檔」),禁用時落 aria-disabled。