「及時」模式:全新世代的 Tailwind CSS
Tailwind CSS on GitHub

Pointer Events

Utilities for controlling whether an element responds to pointer events.

Default class reference

Class
屬性
pointer-events-nonepointer-events: none;
pointer-events-autopointer-events: auto;

Usage

Use pointer-events-auto to revert to the default browser behavior for pointer events (like :hover and click).

Use pointer-events-none to make an element ignore pointer events. The pointer events will still trigger on child elements and pass-through to elements that are “beneath” the target.

Try clicking the caret icon to open the dropdown

pointer-events-auto (event captured)

pointer-events-none (event passes through)

<div class="relative">
  <select class="...">
    <option>Indiana</option>
    <option>Michigan</option>
    <option>Ohio</option>
  </select>
  <div class="pointer-events-auto ...">
    <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"></path></svg>
  </div>
</div>

<div class="relative">
  <select class="...">
    <option>Indiana</option>
    <option>Michigan</option>
    <option>Ohio</option>
  </select>
  <div class="pointer-events-none ...">
    <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"></path></svg>
  </div>
</div>

Customizing

Variants

默認情況下, 只有 響應式 的 pointer event 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 pointerEvents 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       pointerEvents: ['responsive', 'hover'],
      }
    }
  }

Disabling

如果你不打算在專案中使用 pointer event 功能,可以在你的設定檔裡的 corePlugins 屬性中將 pointerEvents 設定為 false 來停用功能:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     pointerEvents: false,
    }
  }