Forum Moderators: open
<script type="text/javascript">
<!--
// global vars
dist = 100;
speed = dist/1.05;
function findPos() {
e = document.getElementById("element");
eTop = e.offsetTop;
eLeft = e.offsetLeft;
}
function left() {
findPos();
e.style.left = eLeft - (dist) + 'px';
return false;
}
function right() {
findPos();
e.style.left = eLeft + (dist) + 'px';
return false;
}
function down() {
findPos();
e.style.top = eTop + (dist) + 'px';
return false;
}
function up() {
findPos();
e.style.top = eTop - (dist) + 'px';
return false;
}
//-->
</script>
<style type="text/css">
* { padding: 0; margin: 0; }
#element {
background: red;
width: 50px;
height: 50px;
position: absolute;
}
#element p { font: bold 10px arial, san-serif; }
</style>
</head>
<body>
<a href="#" onclick="left();">Left</a>
<a href="#" onclick="right();">Right</a>
<a href="#" onclick="up();">Up</a>
<a href="#" onclick="down();">Down</a>
<div id="element"><p>move me</p></div>
</body>
</html>