Skip to content

Instantly share code, notes, and snippets.

@bpierre
Created May 8, 2012 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpierre/2635822 to your computer and use it in GitHub Desktop.
Save bpierre/2635822 to your computer and use it in GitHub Desktop.
CSS Selectors anchors: /mypage.html#anchor-select(#content > h1)
(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