document.addEventListener("DOMContentLoaded", function(event) { var elemToScroll; function scrollToHash(){ var feHeight = $(elemToScroll).offset().top; if ($('header').length && $('header').is(":visible")) { feHeight = feHeight - $('header').outerHeight(); } $('html, body').scrollTop(feHeight); } function closestByClass(el, clazz) { while (el.className !== clazz) { el = el.parentNode; if (!el) { return null; } } return el; } if (location.hash) { setTimeout(function() { window.scrollTo(0, 0); elemToScroll = location.hash; scrollToHash(); }, 1); } var links = document.querySelectorAll('.feature-links.inner .feature-link'); if (links.length > 0){ for (var i = 0; i< links.length; i++){ links[i].addEventListener('click', function(e){ e.preventDefault(); var el = closestByClass(e.target, 'feature-link'); elemToScroll = el.hash; scrollToHash(); }, false); } } //we don't actually need this $('body').on('click', '.article-index li a', function(e){ e.preventDefault(); elemToScroll = e.target.hash; scrollToHash(); }); });