Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TarasKachmar2022 committed Mar 8, 2024
1 parent c5be9a0 commit e49073f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/js/smooth-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ document.querySelectorAll('a.site-nav__link').forEach(link => {

const scrollTarget = document.getElementById(href);

let headerTopOffset = 0;
headerTopOffset = topOffsetSelector();
let topOffset = 0;
topOffset = topOffsetSelector();

const elementPosition = scrollTarget.getBoundingClientRect().top;
const offsetPosition = elementPosition - headerTopOffset;
const offsetPosition = elementPosition - topOffset;

window.scrollBy({ top: offsetPosition, behavior: 'smooth' });
});
});

function topOffsetSelector() {
const viewportWidth = window.innerWidth;

function topOffsetSelector() {
const viewportWidth = window.innerWidth;
let headerTopOffset;

if (viewportWidth >= 768) {
headerTopOffset = 82;
return headerTopOffset;
} else {
headerTopOffset = 104;
return headerTopOffset;
}
if (viewportWidth >= 768) {
headerTopOffset = 82;
return headerTopOffset;
} else {
headerTopOffset = 104;
return headerTopOffset;
}
});
}

0 comments on commit e49073f

Please sign in to comment.