Skip to content

Instantly share code, notes, and snippets.

@Kanol
Created October 31, 2015 15:19
Show Gist options
  • Save Kanol/14ac6b1ba84953137f4b to your computer and use it in GitHub Desktop.
Save Kanol/14ac6b1ba84953137f4b to your computer and use it in GitHub Desktop.
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><style>
.object{
position: absolute;
background-color: red;
width: 100px;
height: 100px;
}
</style>
</head><body><div class="object" style="
top: 0px;
left: 0px;
">
</div>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
function Random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/*
function move(e) {
var random =0;
random = Random(1, 4);
if(random==1) {
y = y + 10;
$object.css('top', y);}
else if (random==2){
y = y - 10;
$object.css('top', y);}
else if (random==3){
x = x + 10;
$object.css('left', x);}
else if (random==4){
x = x - 10;
$object.css('left', x);}
console.log(e);
}
*/
function move(e){
var randX=Random(0, WX);
var randY=Random(0, WY);
x = randX;
y = randY;
$object.css('left', x);
$object.css('top', y);
}
var x = 0;
var y = 0;
var $object = $('.object');
var WX = $(window).width()-100;
var WY = $(window).height()-100;
$object.css('top', y);
$object.css('left', x);
$object.click(move);
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment