|
1238 | 1238 | function initSiteAtmosphereLock() { |
1239 | 1239 | const atmosphere = document.querySelector('.site-atmosphere'); |
1240 | 1240 | const layer = document.querySelector('.site-atmosphere__layer'); |
| 1241 | + const root = document.documentElement; |
1241 | 1242 |
|
1242 | 1243 | if (!atmosphere || !layer) { |
1243 | 1244 | return; |
1244 | 1245 | } |
1245 | 1246 |
|
1246 | 1247 | let rafId = 0; |
1247 | 1248 |
|
| 1249 | + const clamp = (value, min, max) => Math.min(max, Math.max(min, value)); |
| 1250 | + |
1248 | 1251 | const clearInlineOverrides = () => { |
1249 | 1252 | atmosphere.style.removeProperty('transform'); |
1250 | 1253 | atmosphere.style.removeProperty('translate'); |
|
1254 | 1257 | atmosphere.style.removeProperty('margin-top'); |
1255 | 1258 | atmosphere.style.removeProperty('margin-bottom'); |
1256 | 1259 | atmosphere.style.removeProperty('min-height'); |
| 1260 | + atmosphere.style.removeProperty('height'); |
| 1261 | + atmosphere.style.removeProperty('top'); |
1257 | 1262 |
|
1258 | 1263 | layer.style.removeProperty('transform'); |
1259 | 1264 | layer.style.removeProperty('translate'); |
|
1268 | 1273 | layer.style.removeProperty('animation'); |
1269 | 1274 | }; |
1270 | 1275 |
|
1271 | | - const getDocumentHeight = () => { |
1272 | | - const docEl = document.documentElement; |
1273 | | - const bodyEl = document.body; |
1274 | | - |
1275 | | - return Math.max( |
1276 | | - docEl.scrollHeight || 0, |
1277 | | - docEl.offsetHeight || 0, |
1278 | | - docEl.clientHeight || 0, |
1279 | | - bodyEl?.scrollHeight || 0, |
1280 | | - bodyEl?.offsetHeight || 0, |
1281 | | - bodyEl?.clientHeight || 0, |
1282 | | - window.innerHeight || 0 |
1283 | | - ); |
1284 | | - }; |
1285 | | - |
1286 | 1276 | const sync = () => { |
1287 | 1277 | rafId = 0; |
1288 | 1278 | clearInlineOverrides(); |
1289 | 1279 |
|
1290 | | - const fullHeight = Math.ceil(getDocumentHeight()); |
1291 | | - atmosphere.style.height = `${fullHeight}px`; |
| 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 | + |
1292 | 1314 | atmosphere.style.top = '0px'; |
| 1315 | + atmosphere.style.height = `${Math.round(topOffset + boxHeight)}px`; |
1293 | 1316 |
|
1294 | 1317 | body.dataset.siteAtmosphereLocked = '1'; |
1295 | 1318 | }; |
|
1399 | 1422 | const imageScale = lerp(1, 1.125, range(progress, 0, 0.72, easeOutCubic)); |
1400 | 1423 | const baseFade = 1 - range(progress, 0.08, 0.52, linear); |
1401 | 1424 | const baseBrightness = lerp(1, 0.68, range(progress, 0.1, 0.48, easeInOutCubic)); |
1402 | | - const baseContrast = lerp(1, 0.92, range(progress, 0.12, 0.48, easeInOutCubic)); |
1403 | 1425 | const silhouetteAppear = range(progress, 0.2, 0.28, easeInOutCubic); |
1404 | 1426 | const silhouetteFade = 1 - range(progress, 0.28, 0.48, easeInOutCubic); |
1405 | 1427 | const silhouetteOpacity = 0.74 * silhouetteAppear * silhouetteFade; |
|
1411 | 1433 | root.style.setProperty("--home-image-scroll-scale", imageScale.toFixed(4)); |
1412 | 1434 | root.style.setProperty("--home-image-base-layer-opacity", Math.max(0, baseFade).toFixed(4)); |
1413 | 1435 | root.style.setProperty("--home-image-base-brightness", baseBrightness.toFixed(4)); |
1414 | | - root.style.setProperty("--home-image-base-contrast", baseContrast.toFixed(4)); |
1415 | 1436 | root.style.setProperty("--home-image-silhouette-layer-opacity", Math.max(0, silhouetteOpacity).toFixed(4)); |
1416 | 1437 | setAtmosphere(atmosphereProgress); |
1417 | 1438 | setLowerLayer(nextLayerOpacityProgress); |
|
1445 | 1466 | root.style.setProperty("--home-image-scroll-scale", "1"); |
1446 | 1467 | root.style.setProperty("--home-image-base-layer-opacity", "1"); |
1447 | 1468 | root.style.setProperty("--home-image-base-brightness", "1"); |
1448 | | - root.style.setProperty("--home-image-base-contrast", "1"); |
1449 | 1469 | root.style.setProperty("--home-image-silhouette-layer-opacity", "0"); |
1450 | 1470 | setAtmosphere(1); |
1451 | 1471 | setLowerLayer(1); |
|
0 commit comments