Last active
July 5, 2016 12:50
-
-
Save devudit/00c25ec41eb03a56e367b6bee4e3bcb8 to your computer and use it in GitHub Desktop.
Move a html element in circular path using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type="text/css"> | |
#emerico { | |
position: fixed | |
} | |
</style> | |
<div id="emerico">emerico</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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