Skip to content

fix: fade ebg when bg is empty#922

Open
HardyNLee wants to merge 2 commits intoOpenWebGAL:devfrom
HardyNLee:feat/ebg-fading
Open

fix: fade ebg when bg is empty#922
HardyNLee wants to merge 2 commits intoOpenWebGAL:devfrom
HardyNLee:feat/ebg-fading

Conversation

@HardyNLee
Copy link
Copy Markdown
Contributor

介绍

在 bgName 为空时,也能够有 ebg 的淡出动画

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

urlpreviousImageUrl 为空时,使用 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)');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

此处硬编码了 cubic-bezier(0.5, 0, 0.75, 0) 缓动函数,而 setEbg 的默认值以及在 bgName !== '' 分支(第29行)中的调用均使用默认的 ease-in-out。这种不一致可能会导致视觉上的突兀。建议统一使用常量管理缓动函数,或者确保这种差异是符合设计预期的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant