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 從公開儲存庫中收錄這些內容。

檢舉或申請下架