Skip to content

Instantly share code, notes, and snippets.

@FirstWhack
Last active August 29, 2015 13:56
Show Gist options
  • Save FirstWhack/9255385 to your computer and use it in GitHub Desktop.
Save FirstWhack/9255385 to your computer and use it in GitHub Desktop.
dropAnchor() - Secondary anchor `scrollIntoView()-er` for featured listings on a homepage
function dropAnchor(str) { // Eh...
var hash = str || window.location.hash || location.pathname.match(/\/features\/(.*)/)[1];
var links = document.getElementsByTagName('a');
var anchors = [];
for (var i in links) {
var name = links[i].name;
if (name) anchors.push(links[i]);
}
if (hash) {
for (var i in anchors) {
var regex = new RegExp(hash.replace('#', ''), "i");
if (anchors[i].name.match(regex)) {
anchors[i].scrollIntoView();
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment