Skip to content

Instantly share code, notes, and snippets.

@mrtopf
Created August 4, 2010 17:00
Show Gist options
  • Save mrtopf/508442 to your computer and use it in GitHub Desktop.
Save mrtopf/508442 to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
var ball = {
x: 100,
y: 100,
dx : 4,
dy : 4,
};
function moveBall() {
ball.x=ball.x+ball.dx;
ball.y=ball.y+ball.dy;
if (ball.x >1000) {
ball.dx = -ball.dx;
}
if (ball.x <20) {
ball.dx = -ball.dx;
}
if (ball.y <20) {
ball.dy = -ball.dy;
}
if (ball.y >800) {
ball.dy = -ball.dy;
}
$("#ball").css(
{ left: ball.x+"px", top: ball.y+"px" }
);
window.setTimeout(moveBall, 10);
}
$(document).init(function() {
$(document).mousemove(function(e) {
$("#ok").css({left:30+"px", top: (e.clientY-40)+"px"});
});
moveBall();
});
</script>
<body style="background: black; cursor: none;">
<div id="ok" style="position: absolute; top: 200px; left: 30px; width: 20px; height: 80px; background: #fff;">
</div>
<div id="ball" style="position: absolute; top: 400px; left: 130px; width: 10px; height: 10px; background: #fff;">
</div>
</body>
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment