块编辑器开发文档

💡 云策文档标注

概述

本文档介绍了在WordPress界面中添加动画时应遵循的核心原则,旨在通过动画增强层次感和空间定位,提升用户体验。

关键要点

  • 动画应基于真实世界材料设计,明确元素在屏幕外的位置,如菜单从按钮缩放或侧边栏从侧面滑入。
  • 动画必须快速(通常少于0.2秒)、不阻塞用户交互,并优先使用transform CSS属性以确保性能。
  • 保持动画简单,避免不必要的弹跳、旋转或曲线路径,并确保一致性,遵循物理规则以匹配用户期望。
  • 考虑可访问性:动画应微妙,避免触发前庭障碍,不干扰aria-live区域,并尊重OS的“减少动画”设置(如使用prefers-reduced-motion)。
  • 重用现有动画,例如通过通用的Animate组件,以提高界面一致性。

注意事项

  • 如果动画无法做到快速且高性能,应省略它。
  • 避免动画非用户行为直接触发,以减少不必要的干扰。
  • 在Gutenberg中,可利用@reduce-motion mixin来简化“减少动画”设置的实现。

📄 原文内容

Animation can help reinforce a sense of hierarchy and spatial orientation. This document goes into principles you should follow when you add animation.

Principles

Point of Origin

  • Animation can help anchor an interface element. For example a menu can scale up from the button that opened it.
  • Animation can help give a sense of place; for example a sidebar can animate in from the side, implying it was always hidden off-screen.
  • Design your animations as if you’re working with real-world materials. Imagine your user interface elements are made of real materials — when not on screen, where are they? Use animation to help express that.

Speed

  • Animations should never block a user interaction. They should be fast, almost always complete in less than 0.2 seconds.
  • A user should not have to wait for an animation to finish before they can interact.
  • Animations should be performant. Use transform CSS properties when you can, these render elements on the GPU, making them smooth.
  • If an animation can’t be made fast & performant, leave it out.

Simple

  • Don’t bounce if the material isn’t made of rubber.
  • Don’t rotate, fold, or animate on a curved path. Keep it simple.

Consistency

In creating consistent animations, we have to establish physical rules for how elements behave when animated. When all animations follow these rules, they feel consistent, related, and predictable. An animation should match user expectations, if it doesn’t, it’s probably not the right animation for the job.

Reuse animations if one already exists for your task.

Accessibility Considerations

  • Animations should be subtle. Be cognizant of users with vestibular disorders triggered by motion.
  • Don’t animate elements that are currently reporting content to adaptive technology (e.g., an aria-live region that’s receiving updates). This can cause confusion wherein the technology tries to parse a region that’s actively changing.
  • Avoid animations that aren’t directly triggered by user behaviors.
  • Whenever possible, ensure that animations respect the OS-level “Reduce Motion” settings. This can be done by utilizing the prefers-reduced-motion media query. Gutenberg includes a @reduce-motion mixin for this, to be used alongside rules that include a CSS animate property.

Inventory of Reused Animations

The generic Animate component is used to animate different parts of the interface. See the component documentation for more details about the available animations.