Skip to content

Instantly share code, notes, and snippets.

@devudit
Last active July 5, 2016 12:50
Show Gist options
  • Save devudit/00c25ec41eb03a56e367b6bee4e3bcb8 to your computer and use it in GitHub Desktop.
Save devudit/00c25ec41eb03a56e367b6bee4e3bcb8 to your computer and use it in GitHub Desktop.
Move a html element in circular path using jQuery
<style type="text/css">
#emerico {
position: fixed
}
</style>
<div id="emerico">emerico</div>
var p = 0;
function moveit() {
p += 0.05;
var r = 100;
var xcenter = 150;
var ycenter = 150;
var newLeft = Math.floor(xcenter + (r * Math.cos(p)));
var newTop = Math.floor(ycenter + (r * Math.sin(p)));
$('#emerico').animate({
top: newTop,
left: newLeft,
}, 10, function() {
moveit();
});
}
$(document).ready(function() {
moveit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment