|
1236 | 1236 | } |
1237 | 1237 |
|
1238 | 1238 | function initSiteAtmosphereLock() { |
1239 | | - const root = document.documentElement; |
1240 | 1239 | const atmosphere = document.querySelector('.site-atmosphere'); |
1241 | 1240 | const layer = document.querySelector('.site-atmosphere__layer'); |
1242 | 1241 |
|
1243 | 1242 | if (!atmosphere || !layer) { |
1244 | 1243 | return; |
1245 | 1244 | } |
1246 | 1245 |
|
1247 | | - [ |
1248 | | - '--site-atmosphere-viewport-height', |
1249 | | - '--site-atmosphere-viewport-width', |
1250 | | - '--site-atmosphere-render-height', |
1251 | | - '--site-atmosphere-render-width', |
1252 | | - '--site-atmosphere-safe-top', |
1253 | | - '--site-atmosphere-safe-bottom', |
1254 | | - '--site-atmosphere-computed-width', |
1255 | | - '--site-atmosphere-computed-height', |
1256 | | - '--site-atmosphere-computed-offset-y', |
1257 | | - '--site-atmosphere-shift-y' |
1258 | | - ].forEach((name) => { |
1259 | | - root.style.removeProperty(name); |
| 1246 | + let rafId = 0; |
| 1247 | + |
| 1248 | + const clearInlineOverrides = () => { |
| 1249 | + atmosphere.style.removeProperty('transform'); |
| 1250 | + atmosphere.style.removeProperty('translate'); |
| 1251 | + atmosphere.style.removeProperty('left'); |
| 1252 | + atmosphere.style.removeProperty('right'); |
| 1253 | + atmosphere.style.removeProperty('bottom'); |
| 1254 | + atmosphere.style.removeProperty('margin-top'); |
| 1255 | + atmosphere.style.removeProperty('margin-bottom'); |
| 1256 | + atmosphere.style.removeProperty('min-height'); |
| 1257 | + |
| 1258 | + layer.style.removeProperty('transform'); |
| 1259 | + layer.style.removeProperty('translate'); |
| 1260 | + layer.style.removeProperty('left'); |
| 1261 | + layer.style.removeProperty('right'); |
| 1262 | + layer.style.removeProperty('bottom'); |
| 1263 | + layer.style.removeProperty('margin-top'); |
| 1264 | + layer.style.removeProperty('margin-bottom'); |
| 1265 | + layer.style.removeProperty('min-height'); |
| 1266 | + layer.style.removeProperty('max-height'); |
| 1267 | + layer.style.removeProperty('transition'); |
| 1268 | + layer.style.removeProperty('animation'); |
| 1269 | + }; |
| 1270 | + |
| 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 | + const sync = () => { |
| 1287 | + rafId = 0; |
| 1288 | + clearInlineOverrides(); |
| 1289 | + |
| 1290 | + const fullHeight = Math.ceil(getDocumentHeight()); |
| 1291 | + atmosphere.style.height = `${fullHeight}px`; |
| 1292 | + atmosphere.style.top = '0px'; |
| 1293 | + |
| 1294 | + body.dataset.siteAtmosphereLocked = '1'; |
| 1295 | + }; |
| 1296 | + |
| 1297 | + const requestSync = () => { |
| 1298 | + if (rafId) return; |
| 1299 | + rafId = requestAnimationFrame(sync); |
| 1300 | + }; |
| 1301 | + |
| 1302 | + const settledSync = createSettledScheduler(sync); |
| 1303 | + |
| 1304 | + sync(); |
| 1305 | + |
| 1306 | + window.addEventListener('resize', () => { |
| 1307 | + requestSync(); |
| 1308 | + settledSync.schedule(80); |
1260 | 1309 | }); |
1261 | 1310 |
|
1262 | | - atmosphere.style.removeProperty('transform'); |
1263 | | - atmosphere.style.removeProperty('translate'); |
1264 | | - atmosphere.style.removeProperty('top'); |
1265 | | - atmosphere.style.removeProperty('left'); |
1266 | | - atmosphere.style.removeProperty('right'); |
1267 | | - atmosphere.style.removeProperty('bottom'); |
1268 | | - atmosphere.style.removeProperty('margin-top'); |
1269 | | - atmosphere.style.removeProperty('margin-bottom'); |
1270 | | - atmosphere.style.removeProperty('height'); |
1271 | | - atmosphere.style.removeProperty('min-height'); |
1272 | | - |
1273 | | - layer.style.removeProperty('transform'); |
1274 | | - layer.style.removeProperty('translate'); |
1275 | | - layer.style.removeProperty('top'); |
1276 | | - layer.style.removeProperty('left'); |
1277 | | - layer.style.removeProperty('right'); |
1278 | | - layer.style.removeProperty('bottom'); |
1279 | | - layer.style.removeProperty('margin-top'); |
1280 | | - layer.style.removeProperty('margin-bottom'); |
1281 | | - layer.style.removeProperty('height'); |
1282 | | - layer.style.removeProperty('min-height'); |
1283 | | - layer.style.removeProperty('max-height'); |
1284 | | - layer.style.removeProperty('transition'); |
1285 | | - layer.style.removeProperty('animation'); |
1286 | | - |
1287 | | - body.dataset.siteAtmosphereLocked = '1'; |
| 1311 | + window.addEventListener('orientationchange', () => { |
| 1312 | + requestSync(); |
| 1313 | + settledSync.schedule(140); |
| 1314 | + }); |
| 1315 | + |
| 1316 | + window.addEventListener('pageshow', () => { |
| 1317 | + requestSync(); |
| 1318 | + settledSync.schedule(80); |
| 1319 | + }); |
| 1320 | + |
| 1321 | + window.addEventListener('load', () => { |
| 1322 | + requestSync(); |
| 1323 | + settledSync.schedule(120); |
| 1324 | + }); |
1288 | 1325 | } |
1289 | 1326 |
|
1290 | 1327 | function initHomeScrollTransition() { |
|
0 commit comments