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.

有帮助吗?

解决方案

remove 10 from top

$('html,body').animate({
      scrollTop: target.offset().top - 10
    }, 1000);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top