<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Форумы</title>
</head>
<body style="width:100%;">
<style type="text/css">
body{
margin:0;
}
#a1{
height:100px;
width:200px;
background-color:red;
position:relative;
}
#cont{
height:2000px;
width:100%;
background-color:green;
}
</style>
<div id="cont">
<div id="a1" style="left:0px; top:0px;"></div>
</div>
<script type="text/javascript">
window.onload = function(e){
var a1 = document.getElementById("a1");
var cont = document.getElementById("cont");
cont.onmousemove = moveEvent;
var timer;
var xPos;
var yPos;
var posObjx;
var posObjy;
function moveEvent(){
var e;
if(!e){
e = window.event;
}
xPos = e.clientX;
yPos = e.clientY;
timer = setInterval(animateMove,50);
}
function animateMove(){
posObjx = parseInt(a1.style.left);
posObjy = parseInt(a1.style.top);
a1.style.left = posObjx + Math.round((xPos-posObjx)/(1+Math.abs(yPos-posObjy))) + "px";
a1.style.top =posObjy + Math.round((yPos-posObjy)/(1+Math.abs(yPos-posObjy))) + "px";
clearInterval(timer);
}
}
</script>
</body>
</html>