wordpress-grunt/dev/js/main/scrolling.js

24 lines
712 B
JavaScript
Raw Normal View History

2018-04-24 20:41:34 -05:00
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();
}
});
});
});