I have the following code that scrolls to a certain element:
$('html, body').animate({
scrollTop: $("#maincontent").offset().top
}, 400);
However, I have a fixed navbar at the top and so would like to be able to offset this. How can I offset it by a number of pixels?
Try
$("#maincontent").offset().top
just returns an integer, you only need to add or subtract to it to change the offset