Safari does not support scroll-behavior: smooth;
To implement smooth scrolling for internal anchor links, add the following slice of vanilla JavaScript (no jQuery required!):
(function() {
scrollTo();
})();
function scrollTo() {
const links = document.querySelectorAll('.scroll');
links.forEach(each => (each.onclick = scrollAnchors));
}
function scrollAnchors(e, respond = null) {
const distanceToTop = el => Math.floor(el.getBoundingClientRect().top);
e.preventDefault();
var targetID = (respond) ? respond.getAttribute('href') : this.getAttribute('href');
const targetAnchor = document.querySelector(targetID);
if (!targetAnchor) return;
const originalTop = distanceToTop(targetAnchor);
window.scrollBy({ top: originalTop, left: 0, behavior: 'smooth' });
const checkIfDone = setInterval(function() {
const atBottom = window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 2;
if (distanceToTop(targetAnchor) === 0 || atBottom) {
targetAnchor.tabIndex = '-1';
targetAnchor.focus();
window.history.pushState('', '', targetID);
clearInterval(checkIfDone);
}
}, 100);
}
After including that code snippet, any anchor link with a class of .scroll
will scroll to the target. No modifications are required, just drop it in.
Since you have used the class .nav-link
for <a>
tag you can replace scroll in the first line of the scrollTo()
function to your anchor class name which is .nav-link
.
Official source of answer
also do check whether you href
is working fine?