Cybercrux

Everything is achievable through technology

Random Position

<html>
<head>
<script type=”text/javascript”>
function switchPos(obj)
{
var divobj = document.getElementById(‘div1’)
var x = divobj.offsetHeight – obj.height – 5;
var y = divobj.offsetWidth – obj.width – 5;

var randomx = Math.floor(Math.random()*x+1);
var randomy = Math.floor(Math.random()*y+1);

obj.style.top = randomx + ‘px’;
obj.style.left = randomy + ‘px’;
}
</script>
</head>
<body>
<div id=”div1″ style=”width: 800px;height:500px; background: red;”>
<img src=”image.jpg” style=”position:relative;” onmouseover=”switchPos(this);” onmouseout=”switchPos(this);”/>
</div>
</body>
</html>

Leave a comment