# FloatingPanel 懸浮面板
固定底部的懸浮面板,按錨點檔位吸附(錨點幾何 / 吸附換算在
@lh-ui/share/core/floating-panel),根類 lh-floating-panel,
樣式來自 share styles/floating-panel。
懸浮面板(錨點吸附 / 受控檔位 / 內容可拖 / 安全區)
<template>
<div class="demo-col" style="gap: 18px; max-width: 480px">
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="anchorIndex = 0">收合至最低檔</LhButton>
<LhButton size="small" @click="anchorIndex = 1">中檔</LhButton>
<LhButton size="small" @click="anchorIndex = 2">展開最高檔</LhButton>
<LhButton size="small" @click="contentDraggable = !contentDraggable">內容可拖({{ contentDraggable }})</LhButton>
</div>
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="safeArea = !safeArea">安全區留白({{ safeArea }})</LhButton>
<LhButton size="small" @click="disabled = !disabled">停用({{ disabled }})</LhButton>
</div>
<span class="demo-note">
檔位:{{ anchorIndex }} / 即時高度:{{ height }}px(anchors:60px / 40% / 80% 視區高)
</span>
<LhFloatingPanel
:anchors="anchors"
:model-value.sync="anchorIndex"
:content-draggable="contentDraggable"
:safe-area-inset-bottom="safeArea"
:disabled="disabled"
label="篩選面板"
@change="onChange"
@height-change="onHeightChange"
>
<div style="padding: 12px; display: flex; flex-direction: column; gap: 12px">
<p class="demo-note" style="margin: 0">拖動頭部把手或內容區改變面板高度,鬆手吸附最近錨點。</p>
<p class="demo-note" style="margin: 0">頭部具名插槽可自訂把手;contentDraggable=false 時僅頭部可拖。</p>
</div>
</LhFloatingPanel>
</div>
</template>
<script>
export default {
data: () => ({
anchors: [60, '40%', '80%'],
anchorIndex: 1,
contentDraggable: true,
safeArea: true,
disabled: false,
height: 0,
}),
methods: {
onChange(index) {
this.anchorIndex = index
},
onHeightChange(height) {
this.height = Math.round(height)
},
},
}
</script>
# 錨點與吸附
anchors 為高度陣列:數值 = px,'40%' 形式字串 = 視區高度百分比;
內部歸一為升序 px(normalizeAnchors)。拖曳頭部把手時高度
computeDragHeight 跟手(--dragging 關閉高度過渡),鬆手按
resolveSnapIndex 吸附到最近錨點並拋 change / update:modelValue:
<LhFloatingPanel :anchors="[60, '40%', '80%']" @change="onChange" />
# 受控檔位
modelValue 為當前吸附檔位下標(0 起,按錨點升序);受控優先 ——
外部推進覆蓋內部檔位,拖曳提交僅拋事件(.sync 回流裁決):
<LhFloatingPanel :anchors="[60, '40%']" :model-value.sync="index" />
# 拖曳區域與安全區
contentDraggable(預設 true)開啟內容區拖曳,false 時僅頭部
把手可拖;safeAreaInsetBottom(預設 true)追加底部安全區留白
(--safe-area 修飾);disabled 停用拖曳(--disabled 修飾)。
頭部具名插槽 header 預設渲染 __handle 把手條,可自訂。
# Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| anchors | 吸附高度陣列(數值 px 或 '百分比' 字串) | (number \| string)[] | [60, '40%'] |
| modelValue | 當前吸附檔位下標(受控;未傳預設最高檔) | number | — |
| contentDraggable | 內容區可拖曳(false 時僅頭部) | boolean | true |
| safeAreaInsetBottom | 底部安全區留白 | boolean | true |
| disabled | 停用拖曳 | boolean | false |
| label | 無障礙可達名稱(未傳走預設「懸浮面板 第 i/N 檔」) | string | — |
# Events
| 事件 | 說明 | 回呼參數 |
|---|---|---|
| update:modelValue | 檔位變化(受控 .sync) | anchorIndex: number |
| change | 吸附檔位變化 | anchorIndex: number |
| heightChange | 面板高度變化(拖曳跟手 / 吸附落位) | height: number |
# Slots
| 插槽 | 說明 |
|---|---|
| header | 頭部把手區(預設渲染 lh-floating-panel__handle 指示條) |
| default | 面板內容 |
# 無障礙
根元素 role="region" + aria-label(getFloatingPanelAria 生成
「懸浮面板 第 i/N 檔」,label 可覆蓋)。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537