I would like to ask why my page goes up when I clicked it again? I mean if I click on the 'projects' for example then it goes to the projects section which is (0, 590), but If I click it on again or click on skills then it goes up to the top of the page.
const home_view = document.querySelector('.home');
const project_view = document.querySelector('.project');
const skill_view = document.querySelector('.skill');
const about_view = document.querySelector('.about');
const hire_view = document.querySelector('.hire');
home_view.addEventListener('click', () => {
window.scrollTo(0, 0);
});
project_view.addEventListener('click', () => {
window.scrollTo(0, 590);
});
skill_view.addEventListener('click', () => {
window.scrollTo(0, 1250);
});
about_view.addEventListener('click', () => {
window.scrollTo(0, 1750);
});
hire_view.addEventListener('click', () => {
window.scrollTo(0, 2350);
});
Generally, if you want to scroll to specific element, it would be better to use
scrollIntoViewfunctionEx:
Because using
scrollTofor this purpose may not achieve the same result in different screens width.