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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s