문제

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