window.addEventListener('load', function() { var menuLoc = 0; var links = document.getElementById("links").children[0].children; var menu = document.getElementById("menu"); function menuMove(node) { if(menuLoc) return; menu.setAttribute("class", "top"); setTimeout(function() { menu.setAttribute("class", "left") }, 600); menuLoc = 1; } for(var i = 0; i < links.length; i++) { links[i].onclick = function(node) { menuMove(node); }; } }, false);