const menuLinks = document.querySelectorAll( '.menu__link' );
for ( let i = 0; i < menuLinks.length; i++ ) {
menuLinks[i].addEventListener( 'click', function (event) {
event.preventDefault();
const blockId = event.target.getAttribute( 'href' ).substr(1);
document.getElementById( blockId ).scrollIntoView( {
behavior: 'smooth',
block: 'start',
} );
} );
}
const menuLinks = document.querySelectorAll( '.menu__link' ),
header = document.querySelector( '.header' );
for ( let i = 0; i < menuLinks.length; i++ ) {
menuLinks[i].addEventListener( 'click', function ( event ) {
event.preventDefault();
let href = this.getAttribute('href').substring(1);
const scrollTarget = document.getElementById(href);
const topOffset = document.querySelector('.header').offsetHeight;
// const topOffset = 0; // если не нужен отступ сверху
const elementPosition = scrollTarget.getBoundingClientRect().top;
const offsetPosition = elementPosition - topOffset;
window.scrollBy({
top: offsetPosition,
behavior: 'smooth'
});
} );
}