Guest User

Untitled

a guest
Oct 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. var balloon = $('div.balloon'),
  2. x = 0,
  3. y = 0,
  4. dir = 1, // direction
  5. alt = 1 // altitude
  6.  
  7. function animate_balloon(){
  8. // increment x axis
  9. x = x + (1 * dir);
  10.  
  11. // increment y axis
  12. y = y + (1 * alt);
  13.  
  14. balloon.css({
  15. 'margin-top' : y + 'px',
  16. 'margin-left' : x + 'px'
  17. });
  18.  
  19. if(x == 10){
  20. dir = -1;
  21. } else if(x == 0){
  22. dir = 1;
  23. }
  24.  
  25. if(y == 15){
  26. alt = -1;
  27. } else if(y == 0){
  28. alt = 1;
  29. }
  30.  
  31. setTimeout(animate_balloon, 250);
  32. }
  33.  
  34. animate_balloon();
Add Comment
Please, Sign In to add comment