Pergunta

With my javascript code i can scroll to a div, but i need the javascript to get me 20 pixels higher than that div. My code is this

$(function() {
    $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
              if (target.length) {
                $('html,body').animate({
                  scrollTop: target.offset().top
                }, 1000);
                return false;
              }
        }
    });
});

Can someone make it that it get 10px higher than the div? Thank you very much

This is my webpage if you want to know the problem more specific about http://www.sventasticable.nl

My english isn't very good.

Foi útil?

Solução

remove 10 from top

$('html,body').animate({
      scrollTop: target.offset().top - 10
    }, 1000);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top