# @closeio/smart-tooltip-delay 中文文档

规范地址：https://npmcn.com/package/%40closeio/smart-tooltip-delay/

版本：1\.0\.0
npm 元数据更新时间：2026-10-20T16:08:05.751Z
中文译文更新时间：2026-11-10T02:13:33.576Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40closeio/smart-tooltip-delay
原文对照：https://npmcn.com/package/%40closeio/smart-tooltip-delay/?lang=original
项目主页：https://github.com/closeio/smart-tooltip-delay#readme
源码仓库：https://github.com/closeio/smart-tooltip-delay

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：15.6 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- Node.js 要求：\>=8
- 运行依赖：0 个
- 首次发布：2020-09-24T15:58:12.251Z
- 最新版本发布：2020-09-24T15:58:12.694Z
- 近 30 天下载量：48437（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

微风中智能工具提示延迟体验

## 安装

```sh
npm install @closeio/smart-tooltip-delay
```

也可以使用：`pnpm add @closeio/smart-tooltip-delay`、`yarn add @closeio/smart-tooltip-delay`、`bun add @closeio/smart-tooltip-delay`

## README

# 智能工具提示延迟

[![NPM](https://img.shields.io/npm/v/@closeio/smart-tooltip-delay.svg)](https://www.npmjs.com/package/@closeio/smart-tooltip-delay) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-success)](https://prettier.io/)

智能工具提示在微风中延迟体验.

### ![](https://npmcn.com/package/%40closeio/smart-tooltip-delay/smart-tooltip-delay-example.gif)

这个微小的库可以帮助您创建工具提示体验,其中第一个被显示为延迟,随后的任何一个被显示为立即或不同的延迟. 无工具提示活度的确定时间后,恢复原始工具提示延迟.

上面的GIF显示一个智能工具提示延迟,在600ms后显示工具提示,但一旦显示第一个提示,任何后继提示立即显示. 在2500ms没有工具提示活动后,恢复了原来的600ms延迟.

### ![](https://npmcn.com/package/%40closeio/smart-tooltip-delay/close.svg)

有兴趣做这样的项目吗? [关闭](https://close.com/) 正在寻找 [伟大的工程师](https://jobs.close.com/) 加入我们的队伍!

## 安装

```bash
yarn add @closeio/smart-tooltip-delay
```

## 福利

-   极轻(小于400B minzipped).
-   库-不可知性方法——可以结合多个工具提示库,使智能延迟为每个库工作.
-   没有其他第三方依赖关系.

## API 密码

当瞬间 `SmartTooltipDelay`,可以提供3个选项:

1.  `delay` - 每个工具提示的默认延迟
2.  `noDelay` - 为随后显示的每个工具提示(从 `delay` 改为 `noDelay`(中文(简体) )
3.  `resetAfterTime` - 以毫秒计,然后恢复默认延迟的时间(从 `noDelay` 改为 `delay`(中文(简体) )

## 使用量

要与工具提示库相融合,请遵循这些步骤:

1.  `const instance = new SmartTooltipDelay({ delay: 600, noDelay: 0, resetAfterTime: 2500 })`
2.  动态使用工具提示库设置延迟 `instance.getCurrentDelay()` 当用户试图显示工具提示时
3.  显示工具提示时,请拨 `instance.show()`
4.  每当工具提示被隐藏时,请打电话 `instance.hide()`
5.  享受智能工具提示体验

您可以创建单曲 `SmartTooltipDelay` ,或者您可以为每个按钮工具栏创建实例.

### 使用 Tipy.js 的示例

此示例使用单个共享智能延迟和名为Tipy.js的工具提示库.

#### `sharedDelay.js`

```jsx
import SmartTooltipDelay from '@closeio/smart-tooltip-delay';

export default new SmartTooltipDelay({
  delay: 600,
  noDelay: 0,
  resetAfterTime: 2500,
});
```

#### `MyTooltip.js`

```jsx
import sharedSmartDelay from './sharedDelay.js';

export default function MyTooltip({ content /** … more props … */ }) {
  // Show with a smart delay, hide immediately
  const delayArrayRef = useRef([sharedSmartDelay.getCurrentDelay(), 0]);

  // Update Tippy's delay when we try to interact with it.
  const handleOnTrigger = useCallback(() => {
    delayArrayRef.current[0] = sharedSmartDelay.getCurrentDelay();
  }, []);

  // Tell the smart delay that the tooltip has been shown.
  const handleOnShow = useCallback(() => {
    sharedSmartDelay.show();
  }, []);

  // Tell the smart delay that the tooltip has been hidden.
  const handleOnHide = useCallback(() => {
    sharedSmartDelay.hide();
  }, []);

  return (
    <Tippy
      delay={delayArrayRef.current}
      onTrigger={handleOnTrigger}
      onShow={handleOnShow}
      onHide={handleOnHide}
      // … more props
    >
      {content}
    </Tippy>
  );
}
```

### 使用 Bootstrap v2.3.2 的示例 工具提示

这个例子使用一个共享的智能延迟和从"靴子"框架中取出的工具提示.

#### `sharedDelay.js`

```jsx
import SmartTooltipDelay from '@closeio/smart-tooltip-delay';

export default new SmartTooltipDelay({
  delay: 600,
  noDelay: 0,
  resetAfterTime: 2500,
});
```

#### `applySmartDelay.js`

```jsx
import $ from 'jquery';
import sharedSmartDelay from './sharedDelay.js';

/**
 * Extends Bootstrap Tooltip v2.3.2 with smart delay.
 */
export default function applySmartDelay() {
  // Do "Smart" tooltip delay by default.
  $.fn.tooltip.defaults.delay = { show: sharedSmartDelay.getCurrentDelay() };

  // Override Tooltip's `enter` method to sneak in a different "show" delay.
  const Tooltip = $.fn.tooltip.Constructor;
  const _enter = Tooltip.prototype.enter;
  Tooltip.prototype.enter = function (e) {
    const self = $(e.currentTarget).data(this.type);

    if (self && self.options && self.options.hasSmartDelay) {
      self.options.delay = { show: sharedSmartDelay.getCurrentDelay() };
    }

    _enter.call(this, e);
  };

  // Set the "Smart" behaviour without overriding potential custom per-tooltip delay.
  const _getOptions = Tooltip.prototype.getOptions;
  Tooltip.prototype.getOptions = function (initialOptions) {
    const options = _getOptions.call(this, initialOptions);
    // If delay wasn't set, and it is not 0, use smart delay
    options.hasSmartDelay = !initialOptions.delay && initialOptions.delay !== 0;
    return options;
  };

  $(document).on({
    'show.bs.tooltip': sharedSmartDelay.show,
    'hide.bs.tooltip': sharedSmartDelay.hide,
  });
}
```

## 许可证

麻省理工学院 [关闭](https://github.com/closeio)

## 常见问题

### @closeio/smart-tooltip-delay 是什么？

微风中智能工具提示延迟体验

### 如何安装 @closeio/smart-tooltip-delay？

在项目目录运行 npm install @closeio/smart-tooltip-delay，或使用 pnpm add / yarn add / bun add。

### @closeio/smart-tooltip-delay 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/closeio\_\_smart-tooltip-delay 是否存在。

### @closeio/smart-tooltip-delay 支持 ESM 还是 CommonJS？

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

### @closeio/smart-tooltip-delay 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=8。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @closeio/smart-tooltip-delay 可以商用吗？

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

### @closeio/smart-tooltip-delay 的下载量有多少？

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

### @closeio/smart-tooltip-delay 还在维护吗？

最新版本 1\.0\.0 发布于 2020/09/24（6 年前）；至今共发布 1 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/09/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

