|
1 | 1 | <script lang="ts"> |
2 | | - import { onMount } from 'svelte'; |
3 | 2 | import { writable, type Writable } from 'svelte/store'; |
4 | 3 | import { |
5 | 4 | CLICK_MACRO, |
|
52 | 51 | const posterImage = isMobile ? MobileVideoBackupImage : VideoBackupImage; |
53 | 52 | const videoSrc = isMobile ? VideoURLMobile : VideoURL; |
54 | 53 |
|
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) { |
79 | 58 | 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 | | - }); |
104 | 59 | } |
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 | + } |
106 | 107 | </script> |
107 | 108 |
|
108 | 109 | <a |
|
0 commit comments