The following code snippet is designed to enable the sliding of a div inside another hidden overflow div (a concept for a future website). The text box located below the "next" and "previous" links is meant to display the x value.
While everything works correctly on IE8, issues arise with Chrome and Firefox. It appears that the function only executes once (advances by one step) when clicking on both the "next" and "prev" links, indicating that the setTimeout function does not run as intended.
<html>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<head>
<script type="text/javascript">
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
function next(startx, fadeStep, end){
if(startx > end){
startx -= Math.round((1/Math.pow(fadeStep,0.6)));
if (startx < end) startx = end;
document.getElementById('lastname').value = startx + "px";
document.getElementById('test1').style.left = startx + "px";
fadeStep += 0.00035;
args = "next(" + startx + "," + fadeStep + "," + end + ")";
setTimeout(args, 20);
}
}
function prev(startx, fadeStep, end){
if(startx < end){
startx += Math.round((1/Math.pow(fadeStep,0.6)));
if (startx > end) startx = end;
document.getElementById('lastname').value = startx + "px";
document.getElementById('test1').style.left = startx + "px";
setTimeout('prev(' + startx + ',' + (fadeStep+0.00035) + ',' + end + ')', 20);
}
}
</script>
</head>
<body>
<div style="position:relative;width:570;height:78;overflow:hidden">
<div id="test1" style="position:absolute;left:0px;top:0px;width:1180;height:78">
<img src="http://img38.imageshack.us/img38/7225/imageva.png" border=1>
<img src="http://img577.imageshack.us/img577/5554/image2te.png" border=1>
</div>
</div>
<div style="position:absolute;left:900px;top:0px;width:800">
<a href="#" onclick="next(0, 0.001, -570)">Next</a><br />
<a href="#" onclick="prev(-570, 0.001, 0)">Previous</a></ br>
<form><input type="text" id="lastname" value="gfgfg"/></form>
</div>
</body>
</html>
Any assistance you can provide would be greatly appreciated.