Tailwind CSS 指向事件

2022-08-15 10:08 更新

指向事件

用于控制元素是否響應(yīng)指向事件的功能類。

Class
Properties
pointer-events-none pointer-events: none;
pointer-events-auto pointer-events: auto;

使用

使用 ?pointer-events-auto? 來恢復(fù)瀏覽器對指向事件(如 ?:hover? 和 ?click ?)的默認行為。

使用 ?pointer-events-none? 使元素忽略指向事件。指向事件仍然會在子元素上觸發(fā),并傳遞到目標元素的下方。


<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>

自定義

變體

默認情況下, 針對 pointer event 功能類,只生成 responsive 變體。

您可以通過修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?pointerEvents ?屬性來控制為 pointer event 功能生成哪些變體。

例如,這個配置也將生成 hover and focus 變體:

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

禁用

如果您不打算在您的項目中使用 pointer event 功能,您可以通過在配置文件的 ?corePlugins ?部分將 ?pointerEvents ?屬性設(shè)置為 ?false ?來完全禁用它們:

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號