|
7 | 7 | <link rel="manifest" href="/manifest.json" /> |
8 | 8 | <title>WebGAL</title> |
9 | 9 | <style> |
| 10 | + html, |
10 | 11 | body { |
| 12 | + margin: 0; |
11 | 13 | background: black; |
12 | 14 | } |
13 | 15 |
|
|
129 | 131 | .title-enter-container__link-to-github > div { |
130 | 132 | padding: 0 0 0.25em 0; |
131 | 133 | } |
| 134 | + |
| 135 | + html.ios-phone-viewport, |
| 136 | + html.ios-phone-viewport body { |
| 137 | + overflow: hidden; |
| 138 | + overscroll-behavior: none; |
| 139 | + background: black; |
| 140 | + } |
| 141 | + |
| 142 | + html.ios-phone-viewport body { |
| 143 | + width: 2560px; |
| 144 | + height: 1440px; |
| 145 | + position: relative; |
| 146 | + } |
| 147 | + |
| 148 | + html.ios-phone-viewport #ebg { |
| 149 | + display: none; |
| 150 | + } |
| 151 | + |
| 152 | + html.ios-phone-viewport #root, |
| 153 | + html.ios-phone-viewport .html-body__title-enter { |
| 154 | + width: 2560px; |
| 155 | + height: 1440px; |
| 156 | + position: absolute; |
| 157 | + top: 0; |
| 158 | + left: 0; |
| 159 | + transform: none !important; |
| 160 | + transform-origin: top left; |
| 161 | + } |
132 | 162 | </style> |
133 | 163 | </head> |
134 | 164 | <body> |
|
156 | 186 | <!-- 在窗口大小改变时进行强制缩放 --> |
157 | 187 | <script> |
158 | 188 | (() => { |
159 | | - const isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
160 | | - const resize = () => { |
161 | | - const targetHeight = 1440; // 目标高度 |
162 | | - const targetWidth = 2560; // 目标宽度 |
| 189 | + const targetHeight = 1440; |
| 190 | + const targetWidth = 2560; |
| 191 | + const userAgent = navigator.userAgent; |
| 192 | + const platform = navigator.platform; |
| 193 | + const maxTouchPoints = navigator.maxTouchPoints || 0; |
| 194 | + const isIPhoneLike = /iPhone|iPod/i.test(userAgent); |
| 195 | + const isIPadLike = /iPad/i.test(userAgent) || (platform === 'MacIntel' && maxTouchPoints > 1); |
| 196 | + const isIOS = isIPhoneLike || isIPadLike; |
| 197 | + const isIOSPhone = isIOS && isIPhoneLike; |
| 198 | + const html = document.documentElement; |
| 199 | + const body = document.body; |
| 200 | + const root = document.querySelector('#root'); |
| 201 | + const titleEnter = document.querySelector('.html-body__title-enter'); |
| 202 | + const effectBackground = document.querySelector('.html-body__effect-background'); |
| 203 | + let viewportMeta = document.querySelector('meta[name="viewport"]'); |
| 204 | + |
| 205 | + window.__WEBGAL_DEVICE_INFO__ = { isIOS, isIOSPhone }; |
| 206 | + |
| 207 | + const ensureViewportMeta = () => { |
| 208 | + if (!viewportMeta) { |
| 209 | + viewportMeta = document.createElement('meta'); |
| 210 | + viewportMeta.name = 'viewport'; |
| 211 | + document.head.appendChild(viewportMeta); |
| 212 | + } |
| 213 | + return viewportMeta; |
| 214 | + }; |
163 | 215 |
|
| 216 | + const resize = () => { |
164 | 217 | const h = window.innerHeight; // 窗口高度 |
165 | 218 | const w = window.innerWidth; // 窗口宽度 |
166 | 219 | const zoomH = h / targetHeight; // 以窗口高度为基准的变换比 |
|
173 | 226 | let mw2os = targetHeight / 2 - h / 2; // 竖屏时 x轴移动距离 |
174 | 227 | let transform = ''; |
175 | 228 | let effectBackgroundTransform = ''; |
176 | | - const root = document.querySelector('#root'); // 获取根元素 |
177 | | - const titleEnter = document.querySelector('.html-body__title-enter'); |
178 | | - const effectBackground = document.querySelector('.html-body__effect-background'); |
179 | 229 | const elements = [root, titleEnter]; |
180 | 230 | if (w > h) { |
181 | 231 | if (effectBackground) { |
|
224 | 274 | } |
225 | 275 | }; |
226 | 276 | if (!isIOS) { |
227 | | - // 非 IOS |
228 | | - // 创建一个新的 meta 标签 |
229 | | - const metaTag = document.createElement('meta'); |
230 | | - metaTag.name = 'viewport'; |
231 | | - metaTag.content = 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'; |
232 | | - // 将该标签添加到 head 中 |
233 | | - document.head.appendChild(metaTag); |
| 277 | + ensureViewportMeta().content = 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'; |
234 | 278 | resize(); |
235 | 279 | window.onload = resize; |
236 | 280 | window.onresize = resize; |
|
243 | 287 | } |
244 | 288 | }; |
245 | 289 | } else { |
246 | | - // IOS |
247 | | - const metaTag = document.createElement('meta'); |
248 | | - metaTag.name = 'viewport'; |
249 | | - metaTag.content = 'width=device-width, initial-scale=0.22, minimum-scale=0.01, maximum-scale=1'; |
250 | | - // 将该标签添加到 head 中 |
251 | | - document.head.appendChild(metaTag); |
252 | 290 | const styleTag = document.createElement('style'); |
253 | 291 | styleTag.textContent = '* { font-synthesis: none !important; }'; |
254 | 292 | document.head.appendChild(styleTag); |
| 293 | + if (isIOSPhone) { |
| 294 | + html.classList.add('ios-phone-viewport'); |
| 295 | + body.classList.add('ios-phone-viewport'); |
| 296 | + ensureViewportMeta().content = `width=${targetWidth}, height=${targetHeight}, user-scalable=no, viewport-fit=cover`; |
| 297 | + if (effectBackground) { |
| 298 | + effectBackground.style.transform = ''; |
| 299 | + } |
| 300 | + for (const element of [root, titleEnter]) { |
| 301 | + if (element) { |
| 302 | + element.style.left = '0'; |
| 303 | + element.style.top = '0'; |
| 304 | + element.style.transform = 'none'; |
| 305 | + } |
| 306 | + } |
| 307 | + } else { |
| 308 | + ensureViewportMeta().content = 'width=device-width, initial-scale=0.22, minimum-scale=0.01, maximum-scale=1'; |
| 309 | + } |
255 | 310 | } |
256 | 311 | })(); |
257 | 312 | </script> |
258 | 313 | <!-- 注册 Service Worker --> |
259 | 314 | <script> |
260 | 315 | (() => { |
261 | | - const isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
| 316 | + const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
262 | 317 | if ('serviceWorker' in navigator && !isIOS) { |
263 | 318 | navigator.serviceWorker |
264 | 319 | .register('./webgal-serviceworker.js') |
|
274 | 329 | <!-- 首屏加载 --> |
275 | 330 | <script> |
276 | 331 | (() => { |
277 | | - const isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
| 332 | + const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
278 | 333 | let enterPromiseResolve; |
279 | 334 | const enterPromise = new Promise((res) => { |
280 | 335 | enterPromiseResolve = res; |
|
0 commit comments