Maria N Maria N - 1 year ago 143
Javascript Question

jQuery offset top navbar

I've got code for smooth scrolling:

$(window).scroll(function() {
if ($(".nav").offset().top > 150) {
} else {

$(function() {
$('').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');

but after scrolling titles of section are hidden
I need to move it sth about 100px top? i tried:

scrollTop: $($anchor.attr('href')).offset().top-100


scrollTop: $($anchor.attr('href')).offset({top: -100}).top

but this not work correctly :/

Answer Source

You need to add 100 to the top offset because its 0

nav-fixed {

Try this:

$('html, body').stop().animate({
    scrollTop: $(".nav").offset().top + 100
}, 1500, 'easeInOutExpo');

You can check the values your variables with


happy coding!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download