I am trying to write a function that will move an element by adjusting its 'left' style over time. Its currently not working at all in its present form.
var tab;
var tabPos;
function init() {
tab = document.getElementById("tab");
tabPos = 10.8;
tab.style.left = tabPos + '%';
}
function moveOver( ) {
if (tabPos < 15.8)
{
setTimeout(function moveOver( ), 100;
tabPos = tabPos + 0.1;
tab.style.left = tabPos + '%';
}
else if (tabPos > 15.8)
{
setTimeout(function moveOver( ), 100;
tabPos = tabPos - 0.1;
tab.style.left = tabPos + '%';
}
}
The init function successfully sets the initial position of the element but I added the moveOver function to the code the element's position is no longer set.
setTimeout(moveOver, 100);