Как ограничить движение объекта в javascript?
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
var dL = dU = dR = dB = 0;
var L = 123; T = 234; S = 5;
var nL = false, nT = false;
onload = function ()
{
document.body.onkeydown = function (ev)
{
var e = window.event || ev, K = e.keyCode;
if (K == 37) dL = -S;
else if (K == 38) dU = -S;
else if (K == 39) dR = S;
else if (K == 40) dB = S;
}
document.body.onkeyup = function (ev)
{
var e = window.event || ev, K = e.keyCode;
if (K == 37) dL = 0;
else if (K == 38) dU = 0;
else if (K == 39) dR = 0;
else if (K == 40) dB = 0;
}
function move1 ()
{
var p = 'px', O = document.getElementById ('img').style;
L += dL + dR, T += dU + dB;
O.left = L + p; O.top = T + p;
if ((L != 0 || L != 390)||(T != 0 || T != 290)) {
setTimeout (move1, 100);
}
}
move1 ();
}
</script>
</head>
<body>
<div id="pole" style="width : 400px; height : 300px; position : relative; background : #e5e5e5; border : 5px solid #000;">
<div id="img" style="position: absolute; z-index: 999; left: 123px; top: 234px; position : absolytion; width : 10px; height : 10px; border-radius : 50%; background : #000;"></div>
</div>
</body>
</html>