Created
October 13, 2016 14:20
-
-
Save chancesmith/ab3048302d521e445802dcafc41e9a25 to your computer and use it in GitHub Desktop.
Adds top offset to all anchor links clicked (reads URL for anchor link and adds offset of scroll position)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // anchor links offset | |
| $('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-170 }, 1000); | |
| return false; | |
| }); | |
| // Might need a mobile query to handle a different offset | |
| // https://gist.github.com/chancesmith/332d5e312969623f34bf115dcedf4eae |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment