dropAnchor() - Secondary anchor `scrollIntoView()-er` for featured listings on a homepage
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 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