I am currently working on a vertical "progress bar" that will serve as a timeline element. However, I am facing the issue of making it match the height of a specific div rather than the body itself.
Despite numerous attempts, I have yet to find a solution, and I prefer not to share my unsuccessful methods to prevent confusion.
Below is the code that successfully adjusts the bar according to the body's height. I would greatly appreciate any assistance or advice on modifying this code to reflect the height of an individual element:
function adjustHeight() {
var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
var totalHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scrolledPercentage = (winScroll / totalHeight) * 100;
document.querySelector(".progress_bar").style.height = scrolledPercentage + "%";
}
window.addEventListener('scroll', adjustHeight);