Created
March 22, 2016 17:12
-
-
Save endymion1818/696fe63846fe3d07ef87 to your computer and use it in GitHub Desktop.
This JS adds a delay of 500ms when a user clicks any <a> tag on the page, so that you can fire an animation class
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
window.onload = function(){ | |
var links = document.getElementsByTagName('a'); | |
for( var i=0,il = links.length; i< il; i ++ ){ | |
links[i].onclick = clickHandler; | |
} | |
function clickHandler(event) { | |
event.preventDefault(); | |
var travelTo = this.getAttribute("href"); | |
// add `s` to `Element` | |
var animOutUp = document.getElementsByClassName("animateOutUp"); | |
// iterate `animOut` elements | |
for (var i = 0; i < animOutUp.length; i++) { | |
// add `out` `className` to `animOut` element at index `i` | |
animOutUp[i].classList.add("outUp"); | |
}; | |
// add `s` to `Element` | |
var animOutDown = document.getElementsByClassName("animateOutDown"); | |
// iterate `animOut` elements | |
for (var i = 0; i < animOutDown.length; i++) { | |
// add `out` `className` to `animOut` element at index `i` | |
animOutDown[i].classList.add("outDown"); | |
}; | |
// Delay page out until the animation finishes | |
setTimeout(function() { | |
window.location.href = travelTo; | |
}, 500); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment