Last active
October 25, 2015 07:08
-
-
Save edele/085bd1fa7f9d585d5fbf to your computer and use it in GitHub Desktop.
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
| function setHash (hash) { | |
| hash = hash.replace(/^#/, '') | |
| var node = $('#' + hash) | |
| if (node.length) node.attr('id', '') | |
| document.location.hash = hash | |
| if (node.length) node.attr('id', hash) | |
| hash = hash.replace(/^#/, '') | |
| var fx | |
| node = $('#' + hash) | |
| if (node.length) { | |
| node.attr('id', '') | |
| fx = $('<div></div>') | |
| .css({ | |
| position: 'absolute', | |
| visibility: 'hidden', | |
| top: $(document).scrollTop() + 'px' | |
| }) | |
| .attr('id', hash) | |
| .appendTo(document.body) | |
| } | |
| document.location.hash = hash | |
| if (node.length) { | |
| fx.remove() | |
| node.attr('id', hash) | |
| } | |
| } | |
| $('a').click(function (e) { | |
| var href = $(this).attr('href') | |
| var $root = $('html, body') | |
| if (href[0] !== '#' || href.length === 1) { | |
| return true | |
| } | |
| e.preventDefault() | |
| $root.animate({ | |
| scrollTop: $(href).offset().top - 72 | |
| }, 500, function () { | |
| setHash(href) | |
| }) | |
| return false | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
37