I have a location.href code added to identify the section of the page the user is viewing in the URL (www.example.com/#section1, www.example.com/#section2 etc.)
document.getElementById('link_no' + (i + 1)).classList.add('active-link');
let currentLocation = location.href;
currLocationArray = currentLocation.split("#");
currentLocation = currLocationArray[0];
currentLocation += `#section${i+1}`;
location.href = currentLocation;
// scroll section
let sectionOfI = document.getElementById(`section${i+1}`);
let scrollArea = getOffset(sectionOfI);
scrollEventNew(scrollArea.top,e);
but it's messing up the smooth scroll of my JS built scroll function
function scrollEventNew(y , event) {
window.scrollTo({
left: 0,
top: y,
behavior: 'smooth'
})
}
is there a way to keep both codes without commenting out my location.href?
I can't opt for a CSS smooth scroll either.