javascript - Scroll to 100px above the anchor -


i'm using the javascript code below create scroll effect nav anchor.

the problem having want scrolling stop 100px above anchor.

what need change in code achieve result?

$(document).ready(function() {   $('a[href^="#"]').click(function() {       var target = $(this.hash);       if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');       if (target.length == 0) target = $('html');       $('html, body').animate({ scrolltop: target.offset().top }, 1000);       return false;   }); }); 

thank you

subtract 100 pixels target.offset().top. so:

$(document).ready(function() {   $('a[href^="#"]').click(function() {       var target = $(this.hash);       if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');       if (target.length == 0) target = $('html');       $('html, body').animate({ scrolltop: target.offset().top-100 }, 1000);       return false;   }); }); 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -