Created
May 8, 2012 14:48
-
-
Save bpierre/2635822 to your computer and use it in GitHub Desktop.
CSS Selectors anchors: /mypage.html#anchor-select(#content > h1)
This file contains 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(window) { | |
function getSelector(hash) { | |
var matches; | |
hash = hash.slice(1); | |
matches = hash.match(/^anchor-select\((.+)\)$/); | |
if (matches) { | |
return decodeURIComponent(matches[1]); | |
} | |
return false; | |
} | |
function main(hash) { | |
var selector = getSelector(hash); | |
if (selector) { | |
window.document.querySelector(selector).scrollIntoView(true); | |
} | |
} | |
main(window.location.hash); | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment