mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-07-07 11:35:12 +02:00
Added header/footer animation
This commit is contained in:
parent
0640ec6439
commit
531c2295bd
@ -156,4 +156,24 @@ iframe{
|
|||||||
/* start invisible but in the layout (d-none will actually hide it) */
|
/* start invisible but in the layout (d-none will actually hide it) */
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity var(--anim-duration) ease-in-out;
|
transition: opacity var(--anim-duration) ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1. Make sure headers and footers can collapse */
|
||||||
|
header,
|
||||||
|
footer {
|
||||||
|
overflow: hidden;
|
||||||
|
/* choose a max-height that’s >= your tallest header/footer */
|
||||||
|
max-height: 200px;
|
||||||
|
padding: 1rem;
|
||||||
|
transition:
|
||||||
|
max-height var(--anim-duration) ease-in-out,
|
||||||
|
padding var(--anim-duration) ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 2. In fullscreen mode, collapse them */
|
||||||
|
body.fullscreen header,
|
||||||
|
body.fullscreen footer {
|
||||||
|
max-height: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
}
|
}
|
@ -10,47 +10,58 @@ function updateUrlFullscreen(enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter fullscreen: hide header/footer, enable full width, recalc scroll,
|
* Starts a requestAnimationFrame loop that calls your recalc methods,
|
||||||
* set both URL params, update button.
|
* and stops automatically when the header’s max-height transition ends.
|
||||||
*/
|
*/
|
||||||
function enterFullscreen() {
|
function recalcWhileCollapsing() {
|
||||||
// hide header/footer
|
const header = document.querySelector('header');
|
||||||
document.querySelectorAll('header, footer').forEach(el => el.style.display = 'none');
|
if (!header) return;
|
||||||
|
|
||||||
// go full-width
|
// 1) Start the RAF loop
|
||||||
|
let rafId;
|
||||||
|
const step = () => {
|
||||||
|
adjustScrollContainerHeight();
|
||||||
|
updateCustomScrollbar();
|
||||||
|
rafId = requestAnimationFrame(step);
|
||||||
|
};
|
||||||
|
step();
|
||||||
|
|
||||||
|
// 2) Listen for the end of the max-height transition
|
||||||
|
function onEnd(e) {
|
||||||
|
if (e.propertyName === 'max-height') {
|
||||||
|
cancelAnimationFrame(rafId);
|
||||||
|
header.removeEventListener('transitionend', onEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header.addEventListener('transitionend', onEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enterFullscreen() {
|
||||||
|
document.body.classList.add('fullscreen');
|
||||||
setFullWidth(true);
|
setFullWidth(true);
|
||||||
updateUrlFullscreen(true);
|
updateUrlFullscreen(true);
|
||||||
|
|
||||||
// fade in logo
|
// fade in logo… (unchanged)
|
||||||
const logo = document.getElementById('navbar_logo');
|
const logo = document.getElementById('navbar_logo');
|
||||||
if (logo) {
|
if (logo) {
|
||||||
logo.classList.remove('d-none');
|
logo.classList.remove('d-none');
|
||||||
// next frame → trigger transition
|
requestAnimationFrame(() => logo.style.opacity = '1');
|
||||||
requestAnimationFrame(() => {
|
|
||||||
logo.style.opacity = '1';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// recalc scrollbars
|
// now recalc in lock-step with the CSS collapse animation
|
||||||
if (typeof adjustScrollContainerHeight === 'function') adjustScrollContainerHeight();
|
recalcWhileCollapsing();
|
||||||
if (typeof updateCustomScrollbar === 'function') updateCustomScrollbar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exit fullscreen: show header/footer, disable full width, recalc scroll,
|
|
||||||
* clear both URL params, update button.
|
|
||||||
*/
|
|
||||||
function exitFullscreen() {
|
function exitFullscreen() {
|
||||||
// show header/footer
|
document.body.classList.remove('fullscreen');
|
||||||
document.querySelectorAll('header, footer').forEach(el => el.style.display = '');
|
setFullWidth(false);
|
||||||
|
updateUrlFullscreen(false);
|
||||||
|
|
||||||
// fade out logo
|
// fade out logo… (unchanged)
|
||||||
const logo = document.getElementById('navbar_logo');
|
const logo = document.getElementById('navbar_logo');
|
||||||
if (logo) {
|
if (logo) {
|
||||||
logo.style.opacity = '0';
|
logo.style.opacity = '0';
|
||||||
logo.addEventListener('transitionend', function handler(e) {
|
logo.addEventListener('transitionend', function handler(e) {
|
||||||
// only once, and only for opacity
|
|
||||||
if (e.propertyName === 'opacity') {
|
if (e.propertyName === 'opacity') {
|
||||||
logo.classList.add('d-none');
|
logo.classList.add('d-none');
|
||||||
logo.removeEventListener('transitionend', handler);
|
logo.removeEventListener('transitionend', handler);
|
||||||
@ -58,17 +69,10 @@ function exitFullscreen() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset width
|
// recalc while header/footer expand back
|
||||||
setFullWidth(false);
|
recalcWhileCollapsing();
|
||||||
updateUrlFullscreen(false);
|
|
||||||
|
|
||||||
// recalc scrollbars
|
|
||||||
if (typeof adjustScrollContainerHeight === 'function') adjustScrollContainerHeight();
|
|
||||||
if (typeof updateCustomScrollbar === 'function') updateCustomScrollbar();
|
|
||||||
if (typeof syncIframeHeight === 'function') syncIframeHeight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle between enter and exit fullscreen.
|
* Toggle between enter and exit fullscreen.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user