Want to Go Diagonally?

Going in a diagonal direction is just going both horizontally and vertically in one iteration. Here is an example that moves the text from the top-left to the bottom-right of the page.

First, here's the Internet Explorer 5 version:

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!-- Cloaking device on!
function moveTxt()
{
if (ani1.style.pixelTop < 500)
{
ani1.style.pixelTop += 2;
ani1.style.pixelLeft += 2;
setTimeout("moveTxt()", 50);
}
}
// Cloaking device off -->
</script>
</head>
<body onLoad="moveTxt()">
<div id="ani1" style="position:absolute;left:10;top:10">
Text ... on the go!
</div>
</body>
</html>

And here's the Netscape Navigator 4 version:

 <html> <head> <title>A Simple Page</title> ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.