Skip to content

Commit

Permalink
Clarified comments for the heading calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-mon1 committed May 15, 2024
1 parent 4c7e1d2 commit dbc2094
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions themes/digital.gov/src/js/guide-sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ function findTopHeading(

// Recursive case
/* eslint-disable no-param-reassign */
// Calculate the distance of the current heading fro the top of the page
// getBoundingClientRect().top gives the distance from the viewport, so we add the scrollY to get the distance from the top of the page
// Calculate the distance of the current heading from the top of the page
// getBoundingClientRect().top gives the distance from the element to the top of the viewport, then we add the scrollY to get the distance from the top of the viewport to the top of the page
const currentHeadingTop =
headings[i].getBoundingClientRect().top + window.scrollY;

// Calculate the distance of the next heading from the top of the document, if there is a next heading
// Calculate the distance of the next heading from the top of the document, if there is a next heading
// If there is no next heading, set nextHeadingTop to Infinity
const nextHeadingTop =
i < headings.length - 1
Expand Down

0 comments on commit dbc2094

Please sign in to comment.