Skip to content

FloatingPanel - Vant 4

FloatingPanel

Create smooth, interactive bottom panels that enhance your mobile experience! 🚀

📱 Intro

A sleek panel that elegantly floats at the bottom of your page! 🎯 Users can intuitively drag it up and down to reveal content, making it perfect for providing additional functionality, detailed information, or interactive features without cluttering your main interface. ✨

💡 Note: Please upgrade vant to >= v4.5.0 before using this component.

📦 Install

Get started with FloatingPanel in seconds! 🚀 Register the component globally via app.use, or refer to Component Registration for more registration options.

js
import { createApp } from'vue'; import { FloatingPanel } from'vant'; const app = createApp(); app.use(FloatingPanel);

🎯 Usage

Transform your mobile interface with these powerful floating panel patterns! ✨

🌟 Basic Usage

Start with the essentials! 🎪 The default height of FloatingPanel is 100px, and users can intuitively drag it to expand the panel to a height of 60% of the screen height for more content exploration.

html

⚓ Custom Anchors

Create precise stopping points for ultimate user control! 🎯 Set custom anchor positions through the anchors attribute, and control the display height dynamically with v-model:height.

Perfect for multi-level content reveal! 📊 For example, make your panel stop at three strategic positions: 100px, 40% of the screen height, and 70% of the screen height.

html
js
import { ref } from'vue'; exportdefault { setup() { const anchors = [ 100, Math.round(0.4 * window.innerHeight), Math.round(0.7 * window.innerHeight), ]; const height = ref(anchors[0]); return { anchors, height }; }, };

🎛️ Head Drag Only

Fine-tune user interaction! ✋ By default, both the header and content areas are draggable, but you can restrict dragging to just the header area using the content-draggable attribute for more controlled interactions.

html

🔧 API

Complete control over your floating panel's behavior and appearance! 🎛️ Configure every aspect from positioning to interactions with these comprehensive options.

📋 Props

AttributeDescriptionTypeDefault
v-model:heightThe current display height of the panel*numberstring*
anchorsSetting custom anchors, unit pxnumber[][100, window.innerHeight * 0.6]
durationTransition duration, unit second*numberstring*
content-draggableAllow dragging contentbooleantrue
lock-scroll v4.6.4When not dragging, Whether to lock background scrollbooleanfalse
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleantrue

🎪 Events

Stay connected to panel interactions! 🎯 Listen to height changes and user gestures for dynamic responses.

EventDescriptionArguments
height-changeEmitted when panel height is changed and the dragging is finished{ height: number }

🎨 Slots

Unlimited customization possibilities! ✨ Replace default content with your own creative designs and interactive elements.

NameDescription
defaultCustom panel content
headerCustom panel header

📝 Types

Full TypeScript support for type-safe development! 🛡️ Import comprehensive type definitions to ensure your FloatingPanel implementation is robust and error-free.

ts
importtype { FloatingPanelProps } from'vant';

🎨 Theming

🎯 CSS Variables

Customize every visual aspect of your floating panel! 🎨 Use these CSS variables to create the perfect look that matches your brand and design system. Refer to ConfigProvider component for global theming options.

NameDefault ValueDescription
--van-floating-panel-border-radius16px-
--van-floating-panel-header-height30px-
--van-floating-panel-z-index999-
--van-floating-panel-backgroundvar(--van-background-2)-
--van-floating-panel-bar-width20px-
--van-floating-panel-bar-height3px-
--van-floating-panel-bar-colorvar(--van-gray-5)-

Enterprise-level mobile solution based on Vant