...

View Full Version : How To Set Increment Speed ?



coder81
12-17-2006, 07:59 PM
Does anyone know how I can set the increment speed of script below? I want to be able to slow down the speed of i++ and i--.


<script language="javascript">
function down()
{
for (i=30;i<=200;i++) {
document.getElementById('bob').style.top=(i);
}
}
function up()
{
for (i=200;i>=30;i--) {
document.getElementById('bob').style.top=(i);
}
}
</script>
</head>
<body>

<a href="javascript://" onclick="down()">Down</a> | <a href="javascript://" onclick="up()">Up</a>

<div id="bob" style="width:200;height:200;border:solid 1px black;position:absolute;top:30;background:silver"></div>

Any input would be great - Thanks

Arbitrator
12-17-2006, 08:43 PM
Try setInterval()? I used that for a fade script here (http://jsg.byethost4.com/fade+IE.html).

coder81
12-17-2006, 10:43 PM
Arbitrator - I tried setInterval; before I posted this script, but I could never get it to work the right way. I think I put setInterval in the wrong place or I did not implement it right. Do you know how I can apply setInterval to my script and make it delay the i++ and i-- increment speed?

njzy
12-18-2006, 10:00 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<script language="javascript1.2" type="text/javascript">
function down()
{
var speed=5;
var i=document.getElementById('bob').offsetTop;
if (i<=200)
{
document.getElementById('bob').style.top=i+speed;
setTimeout("down()",100);
}
}
function up()
{
var speed=5;
var i=document.getElementById('bob').offsetTop;
if (i>=30)
{
document.getElementById('bob').style.top=i-speed;
setTimeout("up()",100);
}
}
</script>
<a href="javascript://" onclick="down()">Down</a> | <a href="javascript://" onclick="up()">Up</a>
<div id="bob" style="width:200px;height:200px;border:solid 1px black;position:absolute;top:30px;background:silver"></div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum