/* FURY VAPE AUSTRALIA - sticky / fixed-scroll header. v2 OceanWP's theme JavaScript never loads on this host (only jQuery, WooCommerce, wp-emoji and Swiper are enqueued), so everything the theme drives in JS is dead. One victim is the fixed-scroll header: #site-header keeps position:relative and scrolls out of view, even though it carries the classes "fixed-scroll shrink-header" and the theme's .is-sticky / .oceanwp-sticky-header-holder rules are present in the inlined CSS. Once the page scrolls past the top bar, the header is pinned to the top of the viewport and a spacer div takes over the slot the header occupied in flow, so the swap is pixel-neutral and nothing below it moves. Scrolling back to the very top restores the header. Notes for whoever comes next: - There are TWO elements with id="main" on these pages (OceanWP's page template nests a second one inside .entry > article > #content). Always target ".wp-site-blocks > main#main" - getElementById('main') returns the outer one, but the duplicate id means any selector must be explicit. - #main carries "transition: all .3s", so animating its margin-top would slide the whole page for 300ms. A freshly created spacer div has no transition, so the swap is instant. */ (function () { if (window.__furySticky) return; window.__furySticky = true; function ready(fn) { if (document.readyState !== 'loading') fn(); else document.addEventListener('DOMContentLoaded', fn); } ready(function () { var header = document.getElementById('site-header'); var main = document.querySelector('.wp-site-blocks > main#main') || document.getElementById('main'); if (!header || !main || !main.parentNode) return; var spacer = document.createElement('div'); spacer.id = 'fury-header-spacer'; spacer.setAttribute('aria-hidden', 'true'); spacer.style.cssText = 'display:none;width:100%;transition:none!important;'; main.parentNode.insertBefore(spacer, main); var height = 0; // header height while it is in flow var start = 0; // document offset of the header's top (just below the top bar) var pinned = false; function measure() { if (pinned) return; var r = header.getBoundingClientRect(); start = r.top + (window.pageYOffset || document.documentElement.scrollTop || 0); height = r.height; } function pin() { pinned = true; header.style.position = 'fixed'; header.style.top = '0px'; header.style.left = '0px'; header.style.right = '0px'; header.style.width = 'auto'; header.style.zIndex = '999'; spacer.style.height = height + 'px'; spacer.style.display = 'block'; document.body.classList.add('fury-header-pinned'); } function unpin() { pinned = false; header.style.position = ''; header.style.top = ''; header.style.left = ''; header.style.right = ''; header.style.width = ''; header.style.zIndex = ''; spacer.style.display = 'none'; document.body.classList.remove('fury-header-pinned'); } function sync() { var y = window.pageYOffset || document.documentElement.scrollTop || 0; if (!pinned && y > start) pin(); else if (pinned && y <= start) unpin(); } function remeasure() { unpin(); measure(); sync(); } window.addEventListener('scroll', sync, { passive: true }); window.addEventListener('load', remeasure); var t = null; window.addEventListener('resize', function () { clearTimeout(t); t = setTimeout(remeasure, 150); }); measure(); sync(); // late-loading images can change the height of the top bar / header setTimeout(remeasure, 1200); setTimeout(remeasure, 3000); }); })();