Skip to content

Instantly share code, notes, and snippets.

@Jhawins

Jhawins/dropAnchor.js

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.