Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How To Set Increment Speed ?

    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--.

    Code:
    <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

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Try setInterval()? I used that for a fade script here.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <!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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •