静态界面 · 工具条与浮层 · 版式 · 点击
悬浮条
Floating toolbar
浮在目标对象旁边的深色胶囊工具条
- 原理
- 工具条绝对定位在宿主容器里,默认落在目标对象下方 14px;下方空间不够就翻到上方,再不行贴容器底边。整条可拖动,靠近目标对象四边 22px 内出现参考线并吸附。工具按钮是互斥的:点中的那一枚变成红色胶囊,再点一次退出。
- 适用场景
- 编辑器、画布、图片查看、文档阅读、地图、视频剪辑、数据看板;凡是需要贴着对象就近操作的界面都能用
- 手感
- 利落 / 科技
参数
与对象间距
gap · number · px14范围 8 ~ 32吸附阈值
snap · number · px22范围 8 ~ 48胶囊高度
height · number · px40范围 32 ~ 56质量要求
- 减少动态:只有按钮底色与拖动的即时反馈,没有循环动画;系统开启减少动态时不需要额外降级
- 移动端:窄屏隐藏文字与键帽,只留 16px 图标;整条不横向溢出
- 无 JS 兜底:浮条与按钮默认完整可见,停在默认位置;脚本未执行时只是不能拖和切换工具
出处与许可
类型:自研实现 · 自研界面,参考桌面工具浮条的通用形态,未复制他人代码
提示词
请在我的项目里做一个「悬浮条」(Floating toolbar):一条深色胶囊工具条浮在目标对象旁边,默认落在对象下方 14px,空间不够时翻到上方;整条可拖动,靠近对象边缘 22px 内吸附;点工具后按钮变红色胶囊表示当前状态。
参数:与对象间距 14px,吸附阈值 22px,胶囊高度 40px。
要求:用绝对定位放在宿主容器内,不依赖任何库;容器需 position:relative;窄屏隐藏文字只留图标;不抢宿主快捷键。
参考:https://sdjc.xysai.top/web-components/floating-bar.md(原理、参数和参考代码)
274 字符
<div class="fbx" aria-label="悬浮工具条示例">
<div class="fbx-object">
<div class="fbx-chrome"><i></i><i></i><i></i><span>内容画布 · 目标对象</span></div>
<div class="fbx-body">
<div class="fbx-copy">
<p class="fbx-kicker">FLOATING TOOLBAR</p>
<h2>选中对象后,<br>工具就在手边。</h2>
<p class="fbx-sub">不用离开内容,常用操作都在浮条上。</p>
</div>
<div class="fbx-thumb"><span>内容块</span></div>
</div>
<span class="fbx-size">目标对象</span>
<i class="fbx-h is-tl"></i><i class="fbx-h is-tr"></i><i class="fbx-h is-bl"></i><i class="fbx-h is-br"></i>
</div>
<div class="fbx-bar" role="toolbar" aria-label="悬浮工具条">
<button class="fbx-item is-on" type="button" data-tool="select" aria-pressed="true">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="1.4" y="1.4" width="13.2" height="13.2" rx="3.2" stroke-dasharray="3.2 2.4"/></svg>
<span class="fbx-t">选择</span><kbd class="fbx-k">V</kbd>
</button>
<button class="fbx-item" type="button" data-tool="arrow" aria-pressed="false">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3 13 12.6 3.4"/><path d="M8.4 3.4h4.2v4.2"/></svg>
<span class="fbx-t">标注</span><kbd class="fbx-k">A</kbd>
</button>
<button class="fbx-item" type="button" data-tool="pen" aria-pressed="false">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12.4 2.6 13.4 3.6 7.2 11.2 2.9 13 4.3 9.5Z"/></svg>
<span class="fbx-t">画笔</span><kbd class="fbx-k">P</kbd>
</button>
<button class="fbx-item fbx-zoom" type="button" title="比例">
<span class="fbx-num">100%</span>
</button>
<button class="fbx-item fbx-icon" type="button" aria-label="复制">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="5.6" y="2.6" width="7.8" height="7.8" rx="1.4"/><rect x="2.6" y="5.6" width="7.8" height="7.8" rx="1.4"/></svg>
</button>
<button class="fbx-item fbx-icon" type="button" aria-label="保存">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3.1v7.2"/><path d="M5.2 7.7 8 10.5l2.8-2.8"/><path d="M3 12.9h10"/></svg>
</button>
</div>
</div>相关组件