Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Citizen.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 45: Line 45:
}
}


// Helper: Proper scroll to real heading element, ignoring ghost anchors
// Helper: expand parent, wait two frames, scroll manually
function smoothScrollToHeading(heading) {
function smoothScrollToHeading(heading) {
   if (!heading) return;
   if (!heading) return;


   // If the heading has no visible size (hidden anchor), find the first real heading
   // If heading has 0px height (ghost anchor), find next real heading
   if (heading.offsetHeight === 0) {
   if (heading.offsetHeight === 0) {
     const nextHeading = heading.parentElement.querySelector('h1, h2, h3, h4, h5, h6');
     const nextHeading = heading.parentElement.querySelector('h1, h2, h3, h4, h5, h6');
Line 57: Line 57:
   }
   }


   setTimeout(() => {
   // Wait two animation frames for DOM to reflow fully
     heading.scrollIntoView({ behavior: 'smooth', block: 'start' });
  requestAnimationFrame(() => {
     requestAnimationFrame(() => {
      const rect = heading.getBoundingClientRect();
      const scrollTop = window.scrollY + rect.top - 60; // 60px offset for sticky header


    setTimeout(() => {
       window.scrollTo({ top: scrollTop, behavior: 'smooth' });
      const offset = 60; // Adjust this offset if needed
     });
       const maxScrollableUp = window.scrollY;
   });
 
      if (maxScrollableUp > offset) {
        window.scrollBy(0, -offset);
      } else {
        window.scrollTo({ top: 0, behavior: 'smooth' });
      }
     }, 300);
   }, 100); // Minor wait to ensure layout stabilizes
}
}