I have this code:
jQuery('html, body').animate({
scrollTop: jQuery(".woocommerce-breadcrumb").offset().top
}, 777);
But when executed it scrolls too much, how can I make it scroll by 30px less when there is no other element that I could use?
Thank you
2
Answers
Sometimes, vanilla JS does what you want. Just use
scrollIntoView()
:Since you’re scrolling to the
.offset().top
of thewoocommerce-breadcrumb
element, you can subtract some pixels from that offset.Small example were there’s a scroll button below the
woocommerce-breadcrumb
. When clicked, we’ll scroll to the top of the element plus 200px, so eventually the scroll will stop 200 pixels below the top of the element.