Țaman ŞheƦzad Țaman ŞheƦzad - 3 months ago 38
CSS Question

jQuery auto scroll to elements

I came across this useful blog Smoothly scroll to an element without a jQuery plugin

In the below code

scrollTop: $("#target-element").offset().top
}, 1000);

Auto scrolls down to target-element if sliderOn id exists within the body, but, because i have a fixed navbar the target-element goes behind it and cause not to show 20px of the target-element on top. Any solution here?


Try this:

   scrollTop: $("#target-element").offset().top - 20
}, 1000);