Advertisement
consolatio

Jquery box random teleport

Jul 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. .bound{
  5. width:800px;
  6. height:600px;
  7. margin-left:20%;
  8. border:1px solid black;
  9. position:relative;
  10. }
  11. .box{
  12. width:100px;
  13. height:100px;
  14. position:absolute;
  15. background:green;
  16. left:350px;
  17. top:250px;
  18. }
  19. </style>
  20. <script src="jquery.js"></script>
  21. <script>
  22. var x=350;
  23. var y=250;
  24. $(document).ready(function(){
  25. boxFadeOut();
  26. });
  27. function boxFadeIn(){
  28. $(".box").fadeIn(1000,boxFadeOut);
  29. }
  30.  
  31. function boxFadeOut(){
  32. $(".box").fadeOut(1000,changePos);
  33. }
  34.  
  35. function changePos(){
  36. x = Math.round(Math.random()*700);
  37. y = Math.round(Math.random()*500);
  38. //$(".box").css("margin-left",x);
  39. //$(".box").css("margin-top",y);
  40. $(".box").animate({left:x,top:y},0);
  41. boxFadeIn();
  42. }
  43. </script>
  44. </head>
  45. <body>
  46. <div class="bound">
  47. <div class="box">
  48. </div>
  49. </div>
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement