Accordions Dropdowns

dylantarre/animation-principles/skills/07-by-ui-element/accordions-dropdowns

作者 dylantarre83597134ba8f无许可证99 个星标收录于 2026年10月8日更新于 2026年10月8日仓库9个月前更新

Use when animating accordions, collapsibles, dropdowns, or expand/collapse elements for smooth reveal transitions

AI 生成的概览

指导使用迪士尼12项动画原则和CSS技巧,为手风琴、折叠面板和下拉菜单制作展开收起动画。

功能
该技能为手风琴、折叠面板和下拉菜单等展开/收起元素的动画提供指导。它把迪士尼12项动画原则对应到展开过渡上,涵盖挤压拉伸、预备动作、舞台调度、时间与缓动。它还给出实现平滑高度动画的CSS方案,包括grid-template-rows和max-height两种做法,以及箭头旋转和内容淡入。
适用场景
适用于构建或优化需要平滑展开与收起过渡的手风琴、折叠面板或下拉菜单组件。适合对时间、缓动和高度动画质量有要求的前端工作。
运行要求
无需脚本或软件包,仅为说明性内容。CSS示例假定浏览器环境支持grid-template-rows过渡或max-height动画。

Accordion & Dropdown Animation Principles

Apply Disney's 12 principles to expand/collapse elements for smooth, informative reveals.

Principles Applied to Accordions

1. Squash & Stretch

Content can slightly compress as it collapses, stretch as it expands. Trigger header can squash on click feedback.

2. Anticipation

Before expanding, header briefly depresses. Chevron starts rotation before content reveals. Builds expectation.

3. Staging

Expanded section should be clearly visible. Consider dimming other accordion items. Active header stays highlighted.

4. Straight Ahead & Pose to Pose

Define clear states: collapsed, expanding, expanded, collapsing. Pose-to-pose for controlled, reversible animations.

5. Follow Through & Overlapping Action

Container expands first, content fades in 50-100ms later. Chevron rotation can overshoot and settle. Creates depth.

6. Ease In & Ease Out

Expand: ease-out (fast start, smooth finish). Collapse: ease-in (slow start, fast finish). cubic-bezier(0.4, 0, 0.2, 1) works well.

7. Arcs

Chevron rotation should ease through the arc. Content items can enter with slight arc paths rather than straight down.

8. Secondary Action

While content reveals (primary), chevron rotates (secondary), sibling accordions may collapse (tertiary).

9. Timing

  • Expand/collapse: 250-350ms
  • Chevron rotation: 200-250ms
  • Content fade: 150-200ms
  • Stagger internal items: 30-50ms
  • Click feedback: 50ms

10. Exaggeration

Important reveals can use more dramatic timing. FAQ accordions can have snappier animations. Match content importance.

11. Solid Drawing

Maintain consistent header heights. Content should not jitter during height animation. Use proper height techniques.

12. Appeal

Smooth accordions feel polished. Janky height animations feel broken. Proper expand/collapse is worth the technical investment.

CSS Implementation

css
.accordion-content {  display: grid;  grid-template-rows: 0fr;  transition: grid-template-rows 300ms ease-out;}
.accordion-content.open {  grid-template-rows: 1fr;}
.accordion-inner {  overflow: hidden;}
.accordion-chevron {  transition: transform 250ms ease-out;}
.accordion-header[aria-expanded="true"] .accordion-chevron {  transform: rotate(180deg);}
/* Alternative: animate max-height */.dropdown-content {  max-height: 0;  overflow: hidden;  transition: max-height 300ms ease-out;}
.dropdown-content.open {  max-height: 500px; /* larger than content */}

Key Properties

  • grid-template-rows: smooth height
  • max-height: simpler but less precise
  • transform: rotate chevrons
  • opacity: content fade
  • overflow: hidden during transition

来源与署名

来源:dylantarre/animation-principles位于skills/07-by-ui-element/accordions-dropdowns提交8359713

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架