1. 过渡与动画
  2. 过渡时长

过渡与动画

transition-duration

用于控制 CSS 过渡持续时间的工具。

ClassStyles
duration-<number>
transition-duration: <number>ms;
duration-initial
transition-duration: initial;
duration-(<custom-property>)
transition-duration: var(<custom-property>);
duration-[<value>]
transition-duration: <value>;

示例

基本示例

使用类似 duration-150duration-700 的工具设置元素的过渡持续时间(以毫秒为单位):

鼠标悬停在每个按钮上以查看预期行为

duration-150

duration-300

duration-700

<button class="transition duration-150 ease-in-out ...">按钮 A</button>
<button class="transition duration-300 ease-in-out ...">按钮 B</button>
<button class="transition duration-700 ease-in-out ...">按钮 C</button>

使用自定义值

Use the duration-[<value>] syntax to set the 过渡持续时间 based on a completely custom value:

<button class="duration-[1s,15s] ...">
<!-- ... -->
</button>

For CSS variables, you can also use the duration-(<custom-property>) syntax:

<button class="duration-(--my-duration) ...">
<!-- ... -->
</button>

This is just a shorthand for duration-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a transition-duration utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<button class="duration-0 md:duration-150 ...">
<!-- ... -->
</button>

Learn more about using variants in the variants documentation.