Skip to content

Commit 75f9683

Browse files
Merge pull request #818 from HardyNLee/feat/ebg-fading
feat: add ebg fading
2 parents 0162551 + e77a256 commit 75f9683

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

packages/webgal/index.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<link rel="manifest" href="/manifest.json" />
88
<title>WebGAL</title>
99
<style>
10+
body {
11+
background: black;
12+
}
13+
1014
.html-body__effect-background {
1115
height: 100vh;
1216
width: 100vw;
@@ -17,6 +21,20 @@
1721
position: absolute;
1822
top: 0;
1923
left: 0;
24+
background-color: black;
25+
}
26+
27+
.html-body__effect-background-overlay {
28+
height: 100%;
29+
width: 100%;
30+
background-position: center;
31+
background-repeat: no-repeat;
32+
background-size: cover;
33+
position: absolute;
34+
top: 0;
35+
left: 0;
36+
background-color: black;
37+
opacity: 0;
2038
}
2139

2240
.html-body__title-enter {
@@ -115,7 +133,9 @@
115133
</head>
116134
<body>
117135
<!-- 背景模糊 -->
118-
<div class="html-body__effect-background"></div>
136+
<div id="ebg" class="html-body__effect-background">
137+
<div id="ebgOverlay" class="html-body__effect-background-overlay"></div>
138+
</div>
119139
<!-- 落地页 -->
120140
<div class="html-body__title-enter">
121141
<div class="title-enter__initial-background"></div>
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
export function setEbg(url: string) {
2-
const ebg = document.querySelector('.html-body__effect-background') as HTMLElement;
1+
import { DEFAULT_BG_IN_DURATION } from '@/Core/constants';
2+
3+
let previousImageUrl = '';
4+
5+
export function setEbg(url: string, duration = DEFAULT_BG_IN_DURATION) {
6+
const ebg = document.getElementById('ebg') as HTMLElement;
37
if (ebg) {
48
ebg.style.backgroundImage = `url("${url}")`;
59
}
10+
const ebgOverlay = document.getElementById('ebgOverlay') as HTMLElement;
11+
if (ebgOverlay) {
12+
ebgOverlay.style.backgroundImage = `url("${previousImageUrl}")`;
13+
ebgOverlay.animate([{ opacity: 1 }, { opacity: 0 }], {
14+
duration: duration,
15+
easing: 'ease-in-out',
16+
});
17+
}
18+
previousImageUrl = url;
619
}

packages/webgal/src/Stage/MainStage/useSetBg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export function useSetBg(stageState: IStageState) {
2323
}
2424
}
2525
addBg(undefined, thisBgKey, bgName);
26-
setEbg(bgName);
2726
logger.debug('重设背景');
2827
const { duration, animation } = getEnterExitAnimation('bg-main', 'enter', true);
28+
setEbg(bgName, duration);
2929
WebGAL.gameplay.pixiStage!.registerPresetAnimation(animation, 'bg-main-softin', thisBgKey, stageState.effects);
3030
setTimeout(() => WebGAL.gameplay.pixiStage!.removeAnimationWithSetEffects('bg-main-softin'), duration);
3131
} else {

0 commit comments

Comments
 (0)