Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>JavaScript</title>
  5. <style type="text/css">
  6. #b {
  7. width: 1410px;
  8. height: 740px;
  9. margin: 0;
  10. position: absolute;
  11. overflow: hidden;
  12. }
  13.  
  14. #c {
  15. width: 100px;
  16. height: 100px;
  17. background:blue;
  18. margin: 0;
  19. position: relative;
  20. animation-name: example;
  21. animation-duration: 10s;
  22. }
  23.  
  24. /* @keyframes example {
  25. 0% {background-color:blue; left:0px; top:0px;}
  26. 5% {background-color:blue; left:10px; top:0px;}
  27. 10% {background-color:blue; left:10px; top:10px;}
  28. 20% {background-color:blue; left:20px; top:10px;}
  29. 25% {background-color:blue; left:20px; top:20px;}
  30. 30% {background-color:blue; left:30px; top:20px;}
  31. 35% {background-color:blue; left:30px; top:30px;}
  32. 40% {background-color:blue; left:40px; top:30px;}
  33. 45% {background-color:blue; left:40px; top:40px;}
  34. 50% {background-color:blue; left:50px; top:40px;}
  35. 55% {background-color:blue; left:50px; top:50px;}
  36. 60% {background-color:blue; left:60px; top:50px;}
  37. 65% {background-color:blue; left:60px; top:60px;}
  38. 70% {background-color:blue; left:70px; top:60px;}
  39. 75% {background-color:blue; left:70px; top:70px;}
  40. 80% {background-color:blue; left:80px; top:70px;}
  41. 85% {background-color:blue; left:80px; top:80px;}
  42. 90% {background-color:blue; left:90px; top:80px;}
  43. 95% {background-color:blue; left:90px; top:90px;}
  44. 100% {background-color:blue; left:100px; top:100px;}
  45. }*/
  46.  
  47. </style>
  48. </head>
  49. <body>
  50. <div id = "b">
  51. <div id = "c"></div>
  52. </div>
  53.  
  54. <script type="text/javascript">
  55.  
  56. var z = 0;
  57. var a = 0;
  58. var outer = document.getElementById( 'b' );
  59. var inner = document.getElementById( 'c' );
  60. var down = true;
  61. var right = true;
  62. var height = outer.clientHeight - inner.clientHeight;
  63. var width = outer.clientWidth - inner.clientWidth;
  64.  
  65. setInterval( function() {
  66. if ( down ) {
  67. z++;
  68. }
  69. else {
  70. z--;
  71. }
  72.  
  73. if ( z == height ) {
  74. down = false;
  75. }
  76. else if ( z == 0 ) {
  77. down = true;
  78. }
  79.  
  80. if ( right ) {
  81. a++;
  82. }
  83. else {
  84. a--;
  85. }
  86.  
  87. if ( a == width ) {
  88. right = false;
  89. }
  90. else if ( a == 0 ){
  91. right = true;
  92. }
  93. inner.style.marginLeft = a + 'px';
  94. inner.style.marginTop = z + 'px';
  95. }, 1 );
  96.  
  97. </script>
  98.  
  99. </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement