@draggable/tooltip

中文文档
1.2.7发布于 2026/11/06MITESM + CJS构建来源已验证近 30 天下载 3052

A smart tooltip library that automatically positions tooltips optimally within the viewport.

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. Options
  4. Features
  5. Positions
  6. Trigger Types
  7. Hover Trigger
  8. Click Trigger
  9. Cleanup

@draggable/tooltip

A smart tooltip library that automatically positions tooltips optimally within the viewport.

draggable-tooltip

Installation

npm install @draggable/tooltip

Usage

import { Tooltip } from '@draggable/tooltip';

// Initialize with default options
const tooltip = new Tooltip();

// Or with custom options
const tooltip = new Tooltip({
  triggerName: 'custom-tooltip'
});

note: when using umd or iffe, tooltip can be accessed via window.SmartTooltip


## HTML Usage

Add tooltips to any element using data attributes:

```html
<!-- Hover tooltip (default) -->
<div data-tooltip="This is a tooltip">Hover me</div>

<!-- Click tooltip -->
<button data-tooltip="Click tooltip" data-tooltip-type="click">Click me</button>

Options

OptionTypeDefaultDescription
triggerNamestring'tooltip'The name used for the data attribute trigger (e.g., 'tooltip' becomes 'data-tooltip')

Features

  • 🎯 Smart positioning: Automatically finds the best position to display the tooltip
  • 🖱️ Multiple trigger types: Support for both hover and click triggers
  • 📱 Responsive: Automatically repositions on viewport resize and scroll
  • 🎨 Customizable: Easy to style and configure
  • 🔄 8-way positioning: top, bottom, left, right, and corner positions

Positions

The tooltip will attempt to position itself in the following order, choosing the first position that fits within the viewport:

  • top
  • bottom
  • left
  • right
  • top-left
  • top-right
  • bottom-left
  • bottom-right

Trigger Types

Hover Trigger

<div data-tooltip="Hover tooltip">Hover me</div>

Click Trigger

<div data-tooltip="Click tooltip" data-tooltip-type="click">Click me</div>

Cleanup

// Remove event listeners and cleanup
tooltip.destroy();

版本与发布记录

@draggable/tooltip 共发布 11 个版本,首次发布于 2024/11/13;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.7latest2026/11/067 天前
1.2.62026/11/067 天前
1.2.52026/10/2915 天前
1.2.42026/10/2618 天前
1.2.32026/01/209 个月前
1.2.22024/11/162 年前

关于 @draggable/tooltip 的常见问题

@draggable/tooltip 是什么?

A smart tooltip library that automatically positions tooltips optimally within the viewport.

如何安装 @draggable/tooltip?

在项目目录运行 npm install @draggable/tooltip,或使用 pnpm add / yarn add / bun add。

@draggable/tooltip 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/draggable__tooltip 是否存在。

@draggable/tooltip 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@draggable/tooltip 可以商用吗?

@draggable/tooltip 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@draggable/tooltip 的下载量有多少?

根据 npm 官方下载统计,@draggable/tooltip 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,052 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@draggable/tooltip 还在维护吗?

最新版本 1.2.7 发布于 2026/11/06(7 天前);至今共发布 11 个版本,其中过去 12 个月发布了 5 个;首次发布于 2024/11/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。