Skip to content

FloatingBubble - Vant 4

FloatingBubble

🫧 Create magical floating bubbles that dance around your screen! Perfect for quick actions, shortcuts, and interactive elements that follow users everywhere.

🌟 Intro

Meet the FloatingBubble - your new favorite interactive element! 🎯 These delightful clickable bubbles hover gracefully around the edge of your page, providing instant access to important actions. ✨ With smooth dragging, magnetic snapping, and customizable positioning, they create an engaging user experience that's both functional and fun! 🚀

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

📦 Install

Get your floating bubbles ready to soar! 🎈 Register the component globally with app.use(), or explore Component Registration for more flexible installation options.

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

🎨 Usage

✨ Basic Usage

Launch your first floating bubble! 🚀 By default, it appears in the bottom right corner with smooth vertical dragging along the y-axis. Customize the bubble's appearance with the icon prop for the perfect visual touch.

html
js
import { showToast } from'vant'; exportdefault { setup() { constonClick = () => { showToast('Click Bubble'); }; return { onClick }; }, };

🧲 Free Magnetic

Experience the magic of magnetic attraction! ✨ Enable free dragging in both x and y directions, and watch your bubble intelligently snap to the nearest edge of the x-axis - it's like having a smart assistant for your UI!

html
js
import { showToast } from'vant'; exportdefault { setup() { constonOffsetChange = (offset) => { showToast(`x: ${offset.x.toFixed(0)}, y: ${offset.y.toFixed(0)}`); }; return { onOffsetChange }; }, };

🎯 Use v-model

Take full control of your bubble's position! 🎮 Use v-model:offset to programmatically control where your bubble appears and moves - perfect for creating guided tours or dynamic positioning.

html
js
import { ref } from'vue'; exportdefault { setup() { const offset = ref({ x: 200, y: 400 }); return { offset }; }, };

🔧 API

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

📋 Props

AttributeDescriptionTypeDefault
v-model:offsetControl bubble positionOffsetTypeDefault right-bottom coordinate
axisDrag direction, xy stands for free drag, lock stands for disable drag*'x''y'
magneticDirection of automatic magnetic absorption*'x''y'*
iconBubble iconstring-
gapMinimum gap between the bubble and the window, unit px*number{ x: number, y: number }*
teleportSpecifies a target element where BackTop will be mounted*stringElement*

🎪 Events

Listen to user interactions and bubble movements! 🎯 Stay connected to every click and position change for dynamic responses.

EventDescriptionArguments
clickTriggered when a component is clickedMouseEvent
offset-changeTriggered when the position changes due to user dragging{x: string, y: string}

🎨 Slots

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

NameDescription
defaultCustomize the bubble display content

📝 Types

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

ts
exporttype { FloatingBubbleProps, FloatingBubbleAxis, FloatingBubbleMagnetic, FloatingBubbleOffset, } from'vant';

🎨 Theming

🎯 CSS Variables

Customize every visual aspect of your floating bubble! 🎨 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-bubble-size48px-
--van-floating-bubble-initial-gap24px-
--van-floating-bubble-icon-size28px-
--van-floating-bubble-backgroundvar(--van-primary-color)-
--van-floating-bubble-colorvar(--van-background-2)-
--van-floating-bubble-z-index999-
--van-floating-bubble-border-radius--van-floating-bubble-border-radius-

Enterprise-level mobile solution based on Vant