Answers for "smooth scroll to target with offset"

0

smooth scroll to target with offset

function scrollToTargetAdjusted(){
    var element = document.getElementById('targetElement');
    var headerOffset = 45;
    var elementPosition = element.getBoundingClientRect().top;
    var offsetPosition = elementPosition - headerOffset;

    window.scrollTo({
         top: offsetPosition,
         behavior: "smooth"
    });
}
Posted by: Guest on May-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language