From e2281bc901150bafb6f64e62807b32abf22520a7 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 20 Oct 2021 20:43:38 -0400 Subject: fix(html): scrolling to an anchor ensures the line is visible The sticky header was hiding the line scrolled to the top of the window. Along the way, also changed to use classes on to control the sticky header, and moved the header code into a function. --- coverage/htmlfiles/coverage_html.js | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'coverage/htmlfiles/coverage_html.js') diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 514103c7..182e518c 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -277,25 +277,7 @@ coverage.pyfile_ready = function ($) { coverage.assign_shortkeys(); coverage.wire_up_help_panel(); coverage.init_scroll_markers(); - - const sticky = document.querySelector('#sticky_header'); - const header = document.querySelector('header'); - const header_bottom = document.querySelector('header .content .stats').getBoundingClientRect().top; - - function updateHeader() { - if (window.scrollY > header_bottom) { - sticky.classList.add('visible'); - header.classList.add('hidden'); - } else { - sticky.classList.remove('visible'); - header.classList.remove('hidden'); - } - } - - updateHeader(); - window.addEventListener('scroll', function() { - updateHeader(); - }); + coverage.wire_up_sticky_header(); // Rebuild scroll markers when the window height changes. $(window).resize(coverage.build_scroll_markers); @@ -627,3 +609,26 @@ coverage.build_scroll_markers = function () { previous_line = line_number; }); }; + +coverage.wire_up_sticky_header = function () { + const body = document.querySelector('body'); + const header_bottom = ( + document.querySelector('header .content .stats').getBoundingClientRect().top - + document.querySelector('header').getBoundingClientRect().top + ); + + function updateHeader() { + if (window.scrollY > header_bottom) { + body.classList.remove('bighead'); + body.classList.add('littlehead'); + } else { + body.classList.add('bighead'); + body.classList.remove('littlehead'); + } + } + + updateHeader(); + window.addEventListener('scroll', function() { + updateHeader(); + }); +}; -- cgit v1.2.1