---
date: 2025-04-01T05:44:38.945Z
tags:
  - event
---

我找到一个比 css `pointer-events: none` 更好的方案： [`inert`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert)。
它可以阻止 手势输入、聚焦、文本选择，最关键的是，它可以从可访问性树中完全隐藏。

兼容性：chrome 102+, safari 15.5+, firefox 112+

这里给出一些兼容方案：

1. 最简单的方案
   ```css
   [inert] {
     pointer-events: none;
     user-select: none;
   }
   ```
1. 考虑到更多边缘情况的兼容方案

   ```css
   [inert] {
     pointer-events: none;
     cursor: default;
   }

   [inert],
   [inert] * {
     -webkit-user-select: none;
     -moz-user-select: none;
     -ms-user-select: none;
     user-select: none;
   }
   ```

1. 官方 js 垫片方案 [WICG/inert.js](https://github.com/WICG/inert/blob/main/src/inert.js)
   ```js
   import "wicg-inert";
   ```
