WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d0369e8

Browse files
committed
remove onmount and keep subscribe
1 parent 790317d commit d0369e8

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

src/templates/components/Fabric.svelte

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte';
32
import { writable, type Writable } from 'svelte/store';
43
import {
54
CLICK_MACRO,
@@ -52,57 +51,59 @@
5251
const posterImage = isMobile ? MobileVideoBackupImage : VideoBackupImage;
5352
const videoSrc = isMobile ? VideoURLMobile : VideoURL;
5453
55-
onMount(() => {
56-
if (showVideo) {
57-
video.subscribe((video) => {
58-
if (video) {
59-
if (!VideoURL || !VideoURLMobile) return;
60-
61-
video.load(); //
62-
void video.play(); //
63-
64-
const observer = new IntersectionObserver(
65-
(entries) => {
66-
entries.forEach((entry) => {
67-
if (entry.isIntersecting && !played) {
68-
video.paused && void video.play();
69-
} else {
70-
!video.paused && video.pause();
71-
}
72-
});
73-
},
74-
{ root: null, rootMargin: '0px', threshold: 0.2 },
75-
);
76-
observer.observe(video);
77-
}
78-
});
54+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/sveltejs/eslint-plugin-svelte/issues/476
55+
if (showVideo) {
56+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/sveltejs/eslint-plugin-svelte/issues/476
57+
if (isXL) {
7958
post({ type: 'resize', value: { height: 524 } });
80-
} else {
81-
const [backgroundImage, backgroundPosition, backgroundRepeat] = isMobile
82-
? [
83-
MobileBackgroundImage,
84-
MobileBackgroundImagePosition,
85-
MobileBackgroundImageRepeat,
86-
]
87-
: [BackgroundImage, BackgroundImagePosition, BackgroundImageRepeat];
88-
89-
const checkScrollType = (scrollType: string): string =>
90-
scrollType === 'parallax' && (isMobile || isTablet)
91-
? 'fixed'
92-
: scrollType;
93-
94-
post({
95-
type: 'background',
96-
value: {
97-
scrollType: checkScrollType(BackgroundScrollType),
98-
backgroundColor: BackgroundColour,
99-
backgroundImage: `url('${backgroundImage}')`,
100-
backgroundRepeat,
101-
backgroundPosition,
102-
},
103-
});
10459
}
105-
});
60+
video.subscribe((video) => {
61+
if (video) {
62+
if (!VideoURL || !VideoURLMobile) return;
63+
64+
video.load(); //
65+
void video.play(); //
66+
67+
const observer = new IntersectionObserver(
68+
(entries) => {
69+
entries.forEach((entry) => {
70+
if (entry.isIntersecting && !played) {
71+
video.paused && void video.play();
72+
} else {
73+
!video.paused && video.pause();
74+
}
75+
});
76+
},
77+
{ root: null, rootMargin: '0px', threshold: 0.2 },
78+
);
79+
observer.observe(video);
80+
}
81+
});
82+
} else {
83+
const [backgroundImage, backgroundPosition, backgroundRepeat] = isMobile
84+
? [
85+
MobileBackgroundImage,
86+
MobileBackgroundImagePosition,
87+
MobileBackgroundImageRepeat,
88+
]
89+
: [BackgroundImage, BackgroundImagePosition, BackgroundImageRepeat];
90+
91+
const checkScrollType = (scrollType: string): string =>
92+
scrollType === 'parallax' && (isMobile || isTablet)
93+
? 'fixed'
94+
: scrollType;
95+
96+
post({
97+
type: 'background',
98+
value: {
99+
scrollType: checkScrollType(BackgroundScrollType),
100+
backgroundColor: BackgroundColour,
101+
backgroundImage: `url('${backgroundImage}')`,
102+
backgroundRepeat,
103+
backgroundPosition,
104+
},
105+
});
106+
}
106107
</script>
107108

108109
<a

0 commit comments

Comments
 (0)