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: Smooth scroll to heading with slight upward offset
// Helper: Smooth scroll to heading with smart upward offset
function smoothScrollToHeading(heading) {
function smoothScrollToHeading(heading) {
   if (!heading) return;
   if (!heading) return;
Line 52: Line 52:


   setTimeout(() => {
   setTimeout(() => {
     window.scrollBy(0, -60); // Offset upward by 60px
     const offset = 60; // How much we want to adjust upward
   }, 300); // Delay to wait for smooth scroll to finish
    const maxScrollableUp = window.scrollY; // How much room we have to scroll upward
 
    if (maxScrollableUp > offset) {
      window.scrollBy(0, -offset); // Only scroll up if possible
    } else {
      window.scrollTo({ top: 0, behavior: 'smooth' }); // Scroll to top if near the top
    }
   }, 300); // Wait for smooth scroll to finish
}
}


// === Handle direct URL loads with a hash (on page load) ===
// === Handle direct URL loads with a hash (on page load) ===