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
Post a Comment