1const element = document.getElementById('targetElement');
2const offset = 45;
3const bodyRect = document.body.getBoundingClientRect().top;
4const elementRect = element.getBoundingClientRect().top;
5const elementPosition = elementRect - bodyRect;
6const offsetPosition = elementPosition - offset;
7
8window.scrollTo({
9 top: offsetPosition,
10 behavior: 'smooth'
11});