 <p>Explicitly declare all the variables:</p> <pre><code>function animate(num, element, transitionUnit, delayUnit) { var delay = 0; var transition = 0; var x = document.getElementById(element).getElementsByTagName("LI"); for (var i = 0; i &lt;= x.length - 1; i++) { x[i].style.WebkitTransform = "translate3d(" + num + "px,0,0)"; x[i].style.transition = transition + "s " + delay + "s ease-in-out"; delay += delayUnit; transition += transitionUnit; if (x[i].querySelectorAll('ul li').length &gt; 0) { x[i].style.background = "rgba(0,0,0,0.35)"; } } } </code></pre> <p>Using implicit globals in for loops causes problems.</p> <p>As aSeptik mentioned, you might be inverting values:</p> <pre><code>animate(0,"mainNav",0.04,0.02); </code></pre>