(function() { // Nur bei Seitenaufrufen mit Anker if (!window.location.hash) return; const hash = window.location.hash; // Anker vorübergehend aus der URL entfernen, // damit der Browser nicht sofort dorthin springt history.replaceState( null, '', window.location.pathname + window.location.search ); if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; } // Erst nach vollständigem Laden zum Anker window.addEventListener('load', function() { const id = decodeURIComponent(hash.substring(1)); const target = document.getElementById(id); if (!target) { history.replaceState(null, '', hash); return; } // Position nach dem Laden berechnen requestAnimationFrame(function() { requestAnimationFrame(function() { const offset = 100; const position = target.getBoundingClientRect().top + window.scrollY - offset; window.scrollTo(0, Math.max(0, position)); // Anker wieder in URL schreiben, // ohne erneutes Scrollen auszulösen history.replaceState(null, '', hash); }); }); }); })(); jQuery(function($) { const offset = 100; // Ankerlinks innerhalb derselben Seite $(document).on('click', 'a[href*="#"]', function(e) { const url = new URL(this.href, location.href); if ( url.origin !== location.origin || url.pathname !== location.pathname || url.search !== location.search || !url.hash ) return; let target; try { target = document.getElementById( decodeURIComponent(url.hash.substring(1)) ); } catch (error) { return; } if (!target) return; e.preventDefault(); e.stopImmediatePropagation(); $('html, body').stop(true, true); history.pushState(null, '', url.hash); const position = target.getBoundingClientRect().top + window.scrollY - offset; window.scrollTo(0, Math.max(0, position)); }); });

Datenschutz