|
1235 | 1235 | root.style.setProperty('--hero-initial-viewport-height', `${viewportHeight}px`); |
1236 | 1236 | } |
1237 | 1237 |
|
1238 | | - function initSiteAtmosphereLock() { |
1239 | | - const atmosphere = document.querySelector('.site-atmosphere'); |
1240 | | - const layer = document.querySelector('.site-atmosphere__layer'); |
1241 | | - const root = document.documentElement; |
1242 | | - |
1243 | | - if (!atmosphere || !layer) { |
1244 | | - return; |
1245 | | - } |
1246 | | - |
1247 | | - let rafId = 0; |
1248 | | - |
1249 | | - const clamp = (value, min, max) => Math.min(max, Math.max(min, value)); |
1250 | | - |
1251 | | - const clearInlineOverrides = () => { |
1252 | | - atmosphere.style.removeProperty('transform'); |
1253 | | - atmosphere.style.removeProperty('translate'); |
1254 | | - atmosphere.style.removeProperty('left'); |
1255 | | - atmosphere.style.removeProperty('right'); |
1256 | | - atmosphere.style.removeProperty('bottom'); |
1257 | | - atmosphere.style.removeProperty('margin-top'); |
1258 | | - atmosphere.style.removeProperty('margin-bottom'); |
1259 | | - atmosphere.style.removeProperty('min-height'); |
1260 | | - atmosphere.style.removeProperty('height'); |
1261 | | - atmosphere.style.removeProperty('top'); |
1262 | | - |
1263 | | - layer.style.removeProperty('transform'); |
1264 | | - layer.style.removeProperty('translate'); |
1265 | | - layer.style.removeProperty('left'); |
1266 | | - layer.style.removeProperty('right'); |
1267 | | - layer.style.removeProperty('bottom'); |
1268 | | - layer.style.removeProperty('margin-top'); |
1269 | | - layer.style.removeProperty('margin-bottom'); |
1270 | | - layer.style.removeProperty('min-height'); |
1271 | | - layer.style.removeProperty('max-height'); |
1272 | | - layer.style.removeProperty('transition'); |
1273 | | - layer.style.removeProperty('animation'); |
1274 | | - }; |
1275 | | - |
1276 | | - const sync = () => { |
1277 | | - rafId = 0; |
1278 | | - clearInlineOverrides(); |
1279 | | - |
1280 | | - const viewportHeight = Math.max( |
1281 | | - 1, |
1282 | | - Math.round(window.innerHeight || document.documentElement.clientHeight || 0) |
1283 | | - ); |
1284 | | - const viewportWidth = Math.max( |
1285 | | - 1, |
1286 | | - Math.round(window.innerWidth || document.documentElement.clientWidth || 0) |
1287 | | - ); |
1288 | | - const portraitMobile = window.matchMedia('(max-width: 980px) and (orientation: portrait)').matches; |
1289 | | - const landscapeMobile = window.matchMedia('(max-width: 980px) and (orientation: landscape)').matches; |
1290 | | - |
1291 | | - const totalEffectHeight = portraitMobile |
1292 | | - ? clamp(viewportHeight * 0.44, 260, 430) |
1293 | | - : landscapeMobile |
1294 | | - ? clamp(viewportHeight * 0.4, 210, 320) |
1295 | | - : clamp(viewportHeight * 0.41, 240, 390); |
1296 | | - |
1297 | | - const topOffset = portraitMobile |
1298 | | - ? clamp(viewportHeight * 0.028, 12, 26) |
1299 | | - : landscapeMobile |
1300 | | - ? clamp(viewportHeight * 0.045, 14, 26) |
1301 | | - : clamp(viewportHeight * 0.05, 18, 34); |
1302 | | - |
1303 | | - const boxHeight = Math.max(160, Math.round(totalEffectHeight - topOffset)); |
1304 | | - const width = portraitMobile |
1305 | | - ? clamp(viewportWidth * 1.88, 580, 1200) |
1306 | | - : landscapeMobile |
1307 | | - ? clamp(viewportWidth * 1.58, 900, 1800) |
1308 | | - : clamp(viewportWidth * 1.52, 1100, 2200); |
1309 | | - |
1310 | | - root.style.setProperty('--site-atmosphere-top', `${Math.round(topOffset)}px`); |
1311 | | - root.style.setProperty('--site-atmosphere-box-height', `${Math.round(boxHeight)}px`); |
1312 | | - root.style.setProperty('--site-atmosphere-width', `${Math.round(width)}px`); |
1313 | | - |
1314 | | - atmosphere.style.top = '0px'; |
1315 | | - atmosphere.style.height = `${Math.round(topOffset + boxHeight)}px`; |
1316 | | - |
1317 | | - body.dataset.siteAtmosphereLocked = '1'; |
1318 | | - }; |
1319 | | - |
1320 | | - const requestSync = () => { |
1321 | | - if (rafId) return; |
1322 | | - rafId = requestAnimationFrame(sync); |
1323 | | - }; |
1324 | | - |
1325 | | - const settledSync = createSettledScheduler(sync); |
1326 | | - |
1327 | | - sync(); |
1328 | | - |
1329 | | - window.addEventListener('resize', () => { |
1330 | | - requestSync(); |
1331 | | - settledSync.schedule(80); |
1332 | | - }); |
1333 | | - |
1334 | | - window.addEventListener('orientationchange', () => { |
1335 | | - requestSync(); |
1336 | | - settledSync.schedule(140); |
1337 | | - }); |
1338 | | - |
1339 | | - window.addEventListener('pageshow', () => { |
1340 | | - requestSync(); |
1341 | | - settledSync.schedule(80); |
1342 | | - }); |
1343 | | - |
1344 | | - window.addEventListener('load', () => { |
1345 | | - requestSync(); |
1346 | | - settledSync.schedule(120); |
1347 | | - }); |
1348 | | - } |
1349 | | - |
1350 | 1238 | function initHomeScrollTransition() { |
1351 | 1239 | const root = document.documentElement; |
1352 | 1240 | const hero = document.querySelector("#hero"); |
|
2429 | 2317 |
|
2430 | 2318 | async function boot() { |
2431 | 2319 | initHeroViewportLock(); |
2432 | | - initSiteAtmosphereLock(); |
2433 | 2320 |
|
2434 | 2321 | await Promise.all([ |
2435 | 2322 | injectPartial('#nav-slot', 'nav.html'), |
|
0 commit comments