when i click the close button in the pop up container the scroll position goes back at the top
this is my html code for the pop up container
<div id="popup-container" class="popup-container">
<div class="popup-content">
<!-- Add content for exercises -->
<h3 id="popup-title">Exercise Details</h3>
<p id="Exercise1"></p>
<p id="Exercise2"></p>
<p id="Exercise3"></p>
<p id="Exercise4"></p>
<p id="Exercise5"></p>
<p id="Exercise6"></p>
<!-- Close button -->
<a href="#" class="close-btn" onclick="closePopup()">Close</a>
</div>
</div>
var scrollPosition;
function openPopup(title, Exercise1, Exercise2, Exercise3, Exercise4, Exercise5, Exercise6) {
// Save the current scroll position
scrollPosition = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
// Set the content of the popup
document.getElementById('popup-title').textContent = title;
document.getElementById('Exercise1').textContent = 'Exercise: ' + Exercise1;
document.getElementById('Exercise2').textContent = 'Exercise: ' + Exercise2;
document.getElementById('Exercise3').textContent = 'Exercise: ' + Exercise3;
document.getElementById('Exercise4').textContent = 'Exercise: ' + Exercise4;
document.getElementById('Exercise5').textContent = 'Exercise: ' + Exercise5;
document.getElementById('Exercise6').textContent = 'Exercise: ' + Exercise6;
// Display the popup
document.getElementById('popup-container').style.display = 'flex';
// Add an event listener to track changes in the scroll position
window.addEventListener('scroll', handleScroll);
}
function closePopup() {
// Hide the popup
document.getElementById('popup-container').style.display = 'none';
// Remove the scroll event listener
window.removeEventListener('scroll', handleScroll);
}
function handleScroll() {
// Restore the scroll position
window.scrollTo(0, scrollPosition);
}
this is my javascript for my pop up container
I want that wehn i close the button, it stays at its scroll position