wordpress-grunt/dev/js/main/scrolling.js
2018-04-26 19:52:56 -05:00

24 lines
712 B
JavaScript

document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll('[href^="#"]').forEach(function(link){
link.addEventListener('click', function(event){
var target = document.querySelector(this.getAttribute('href'));
if(target !== null){
target.scrollIntoView({
behavior: 'smooth'
});
window.setTimeout(function(){
var index = target.getAttribute('tabindex');
target.setAttribute('tabindex', -1);
target.focus();
target.setAttribute('tabindex', index);
history.pushState({},null,"#" + target.getAttribute('id'));
}, 800);
event.preventDefault();
}
});
});
});