Move Left or Right

This is a simple animation using plain javascript and html.


move.html
<html>
<head>
<title>Dagan2x</title>
<script language="JavaScript">
var slideSpeed = 0;
function move(location) {
var span1 = document.getElementById('span1');
if(location == "left")
{
slideSpeed = -5;
}
else
{
slideSpeed = 5;
}

slide();

}

function slide()
{
if(slideSpeed != 0)
{
span1.style.left = (span1.offsetLeft + slideSpeed) + "px";
setTimeout('slide()',20);
}
}

</script>
</head
<body>
<span id="span1" style="position:absolute;">Modagan Ko!</span>
<br />
<br />
<button onmouseover="move('left');" onmouseout="slideSpeed=0;" onclick="slideSpeed=0;"><< Left</button>

<button onmouseover="move('right');" onmouseout="slideSpeed=0;" onclick="slideSpeed=0;">Right >></button>
</body>
</html>

No comments:

Post a Comment