Toast 和 Notification 怎么选? 在网页端,尤其是给操作反馈时,我们常用 Toast 或 Notification 传递信息。两者的使用场景有什么区别? Toast 用于即时、直接的反馈:展示某个操作的结果,用户知道即可。它可以附带一个按钮(比如撤销),配合倒计时,到时自动消失,避免打扰。耗时的操作,也可以先显示进度,完成后原地变为结果。 如果某件事必须由用户处理,就不适合用 Toast:不可撤销的操作,应在执行前用弹窗确认;需要处理的失败,应留在原处,直到解决。 Notification 常见于操作系统,一些工作台类产品也会使用。它与 Toast 最大的区别在于:内容可以与用户当前的操作无关,由他人或系统主动发出,而不是由用户的操作触发。因此,它适合展示需要用户看到、但不必立刻打断的信息,这也是它与弹窗的区别。Notification 会一直保留,直到用户处理或关闭;多条可以堆叠,也可以附带操作按钮。 附一条 Prompt:它会先读取你的产品,逐条判断每条提示该用 Toast、Notification 还是都不用,列出表格由你决定;确认后,还可以按视频中的效果改造 Toast 和 Notification。完整 Prompt 见评论,可以直接复制。
枯白啃设计

图标设计师 / 设计工程师

Prompt(3/3) - Hover: the stack spreads into a list at the cards' own heights, 8 apart, in 380ms on the same curve. In the list each card keeps to a hairline and a light shadow, so no shadow falls on the card below; stacked, only the front card has the deep shadow. - Close one, as on macOS: a small close button (24, 10 corners) appears over a card's top-left corner while the pointer is on that card. Handling a card with one of its buttons also removes it. A removed card slides 48px to the right and fades in 260ms, and the ones below close the gap in 400ms. "Clear all" sits under the last card while the list is spread out. - Counts: the bell shows how many are waiting, and so does the page title, so a tab in the background shows it too. Notifications that need a decision (security, payments) stay in the list behind the bell even when they are cleared from the screen. 4C. For both - Reduced motion: keep the change of state and a short fade (about 150ms); drop the movement, scaling and blur. - Screen readers: toasts are announced politely (role="status"); a notification that needs attention is announced once as it arrives. Neither takes focus away from what the person is doing. Their buttons can be reached by keyboard, and Escape closes the one in focus. - Touch: the same places, with swipe to dismiss; there is no hover, so the stack spreads on tap. - Dark mode: the same rules on my dark surfaces; the sheen is fainter. 5. Build what I pick - List the files you will touch and wait for my go-ahead. - Change one thing at a time and keep what each action does. Then check: - Short and long text, a missing picture, many notifications at once, several toasts in a row. - Undo used, ignored and closed; a progress that fails; leaving the page while something is still running. - Phone and desktop layouts, light and dark, reduced motion, keyboard and screen reader. - Existing tests still pass. - Web: CSS transitions or the Web Animations API for the toast; for the stack, measure each card's height and animate transform and height together. Sonner (React) has a similar stack and can be adapted, but ask before adding it. iOS, Android and Flutter: use the platform's own animation tools with the same values; for messages that reach people outside the app, use the system's notifications.
登录并发表评论

评论 · 0