Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves background transition handling by tracking and canceling active animations in setEbg and allowing for custom easing functions. The useSetBg hook was also updated to synchronize background removal durations. Feedback was provided regarding the need for non-empty checks on image URLs to prevent invalid resource requests and unnecessary animations. Additionally, it was suggested to use constants for easing functions to ensure visual consistency across different parts of the application.
Comment on lines
9
to
21
| 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 }], { | ||
| if (animation) { | ||
| animation.cancel(); | ||
| } | ||
| animation = ebgOverlay.animate([{ opacity: 1 }, { opacity: 0 }], { | ||
| duration: duration, | ||
| easing: 'ease-in-out', | ||
| easing: ease, | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
当 url 或 previousImageUrl 为空时,使用 url("") 可能会导致浏览器产生无效的资源请求。此外,如果 previousImageUrl 为空,意味着没有前一个背景,此时执行淡出动画是没有意义的。建议在设置背景图时进行非空检查,并仅在有前置背景图时执行动画。
ebg.style.backgroundImage = url ? `url("${url}")` : 'none';
}
const ebgOverlay = document.getElementById('ebgOverlay') as HTMLElement;
if (ebgOverlay) {
if (previousImageUrl) {
ebgOverlay.style.backgroundImage = `url("${previousImageUrl}")`;
if (animation) {
animation.cancel();
}
animation = ebgOverlay.animate([{ opacity: 1 }, { opacity: 0 }], {
duration: duration,
easing: ease,
});
} else {
ebgOverlay.style.backgroundImage = 'none';
if (animation) {
animation.cancel();
animation = null;
}
}
}| removeBg(currentBg); | ||
| exitDuration = removeBg(currentBg); | ||
| } | ||
| setEbg(bgName, exitDuration, 'cubic-bezier(0.5, 0, 0.75, 0)'); |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
介绍
在 bgName 为空时,也能够有 ebg 的淡出动画