Created
March 13, 2013 03:45
-
-
Save gawaooooo/5149242 to your computer and use it in GitHub Desktop.
JavaScriptで横揺れ
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
count = 0 | |
degree = 0 | |
radian = 0 | |
speed = 25 | |
radius = 5 | |
beforeLeft = @targetEnemy.css('left') | |
# centerX = parseInt(@targetEnemy.css('left'), 10) /2 | |
x = (if beforeLeft is 'auto' then 0 else parseInt(beforeLeft, 10)) | |
timer = setInterval(=> | |
if count <= 100 | |
degree += speed | |
# degreeは0~360 | |
degree = (degree % 360 + 360) % 360 | |
radian = degree * Math.PI / 180 | |
@targetEnemy.css | |
left: x + (Math.cos(radian) * radius) + 'px' | |
count += 1 | |
else | |
clearInterval timer if count > 100 | |
, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment