You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular中reveal触发器过渡动画未应用缓动效果问题

Fixing the Missing Easing on the reveal Trigger in Your Angular Sidebar

Hey there! Looking at your code, the reason your reveal trigger isn’t applying the easing effect is because you’re missing transition definitions for key state changes. Let’s break this down and fix it:

What’s Going Wrong?

Right now, your reveal animation only handles thin → full and full → collapse transitions. When you switch from full to thin, there’s no transition configured—so Angular just jumps straight to the thin state styles without any easing. While it’s less visible, there’s also no transition for collapse → thin (we’ll fix that for completeness).

The Fix

Update the reveal trigger in your PanelLinkComponent to cover all necessary state transitions, and use bidirectional transitions to keep the code clean:

trigger(
  'reveal', [
    // Combine collapse and thin states since their styles are identical
    state('collapse, thin', style({
      width: 0,
      opacity: 0,
      'margin-left': 0,
      'margin-right': 0,
    })),
    state('full', style({
      width: '100%',
      opacity: 1,
      'margin-left': '15px',
      'margin-right': '10px',
    })),
    // Bidirectional transition for thin ↔ full (uses ease-out both ways)
    transition('thin <=> full', animate('500ms ease-out')),
    // Keep the existing full → collapse transition with ease-in
    transition('full => collapse', animate('500ms ease-in')),
    // Collapse → thin doesn't need animation, but define it explicitly
    transition('collapse => thin', animate('0ms'))
  ]
)

Extra Tips to Smooth Things Out

  • Span Display Fix: Make sure the span element is a block-level element so width transitions work properly. Add this to your PanelLinkComponent CSS:
    mat-list-item span {
      display: inline-block;
      white-space: nowrap;
      overflow: hidden;
    }
    
  • Sync State Updates: Double-check that the state input passed to panel-link updates synchronously with the sidebar’s state. Any delay could prevent the animation from triggering correctly.
  • Simplify State Logic: By combining collapse and thin states in the animation, you reduce redundant code and make maintenance easier.

After these changes, your reveal animation should apply the easing effect just like your slide triggers do.

内容的提问来源于stack exchange,提问作者Jaime Still

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:06:36