-
-
Notifications
You must be signed in to change notification settings - Fork 315
feat: add ebg fading #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ebg fading #818
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,19 @@ | ||
| export function setEbg(url: string) { | ||
| const ebg = document.querySelector('.html-body__effect-background') as HTMLElement; | ||
| import { DEFAULT_BG_IN_DURATION } from '@/Core/constants'; | ||
|
|
||
| let previousImageUrl = ''; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用模块级别的变量 虽然在当前的使用场景下(可能只有一个地方调用它),这可能不会造成问题,但如果未来有多个独立的组件需要调用 为了提高代码的健壮性和可维护性,建议将状态管理与函数逻辑分离。例如,可以创建一个 |
||
|
|
||
| export function setEbg(url: string, duration = DEFAULT_BG_IN_DURATION) { | ||
| const ebg = document.getElementById('ebg') as HTMLElement; | ||
| if (ebg) { | ||
| ebg.style.backgroundImage = `url("${url}")`; | ||
| } | ||
| const ebgOverlay = document.getElementById('ebgOverlay') as HTMLElement; | ||
| if (ebgOverlay) { | ||
| ebgOverlay.style.backgroundImage = `url("${previousImageUrl}")`; | ||
| ebgOverlay.animate([{ opacity: 1 }, { opacity: 0 }], { | ||
| duration: duration, | ||
| easing: 'ease-in-out', | ||
| }); | ||
| } | ||
| previousImageUrl = url; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个新的 CSS 类
.html-body__effect-background-overlay与现有的.html-body__effect-background类(第 14-25 行)之间存在大量重复的样式属性,例如background-position,background-repeat,background-size,position等。代码重复会增加未来维护的难度,当需要修改这些共享样式时,不得不在多个地方进行同步修改,容易出错。
为了遵循 DRY (Don't Repeat Yourself) 原则,建议进行重构。一个可能的方案是创建一个通用的类来包含共享的样式,然后让
.html-body__effect-background和.html-body__effect-background-overlay都使用这个通用类,从而消除重复。