Hi, i was wondering how you could make a layer on the screen move using javascript??
any ideas??
Martin
Computing/Gaming help and info:
any ideas??
Martin
Computing/Gaming help and info:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function moveDiv()
{
var mousex = event.x;
var mousey = event.y;
window.status = "x:"+mousex+"/y:"+mousey; //sanity-check
[b]rainbowDiv.style.left = mousex - (rainbowDiv.offsetWidth/2);
rainbowDiv.style.top = mousey - (rainbowDiv.offsetHeight/2);[/b]
}//end rainbow
[b]document.onmousemove = moveDiv;[/b]
</script>
</head>
<body>
<div style="[b]position:absolute;[/b]width:50px;height:50px;background-color:red;" id="rainbowDiv"></div>
Hello, World!
</body>
</html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
var divx;
var divy;
var increment;
var dt = 10; [b]//dt is change in time[/b]
var time = 5000; [b]//time is in milliseconds, so 5000 is 5 seconds[/b]
function moveDiv()
{
[b]//determines how much DIV will move at each stage[/b]
increment = Math.round((document.body.clientHeight-rainbowDiv.offsetHeight)/(time/dt));
divx = document.body.clientWidth - rainbowDiv.offsetWidth;
divy = document.body.clientHeight - rainbowDiv.offsetHeight;
window.status = "x:"+divx+"/y:"+divy; //sanity-check
rainbowDiv.style.left = divx;
rainbowDiv.style.top = divy;
startMoveUp();
}//end moveDiv()
var timeoutObject;
var timer = 0;
function startMoveUp()
{
if(timer < time)
{
timer += dt;
divy = divy - increment;
window.status = "x:"+divx+"/y:"+divy; //sanity-check
rainbowDiv.style.top = divy; [b]//moves it once[/b]
timeoutObject = setTimeout("startMoveUp()", dt); [b]//schedules it to move again[/b]
}//end if
else
{
clearTimeout(timeoutObject);
timer = 0;
startMoveDown();
}//end else
}//end startMove()
function startMoveDown()
{
if(timer < time)
{
timer += dt;
divy = divy + increment;
window.status = "x:"+divx+"/y:"+divy; //sanity-check
rainbowDiv.style.top = divy; [b]//moves it once[/b]
timeoutObject = setTimeout("startMoveDown()", dt); [b]//schedules it to move again[/b]
}//end if
else
{
clearTimeout(timeoutObject);
timer = 0;
window.status = "Finished."; //sanity check
[b]//NOTE: only iterates once[/b]
}//end else
}//end startMoveDown()
</script>
</head>
<body [b]onload='moveDiv()'[/b]>
<div style="position:absolute;width:50px;height:50px;background-color:red;" id="rainbowDiv"></div>
Hello, World!
</body>
</html>
function pauseSlider()
{
if(timer < time)
{
timer += dt;
timeoutObject = setTimeout("pauseSlider()", dt);
}//end if
else
{
clearTimeout(timeoutObject);
timer = 0;
startMoveDown();
}//end else
}//end pausesSlider()