Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. //calling the function in window.onload to make sure the HTML is loaded
  2. window.onload = function() {
  3. var posLeft = 0;
  4. var posTop = 150;
  5. //our box element
  6. var box = document.getElementById('box');
  7. var t = setInterval(move, 10);
  8. var moveDown = setInterval(cac, 10);
  9.  
  10. function move() {
  11. if(posLeft >= 150) {
  12. clearInterval(t);
  13. }
  14. else {
  15. posLeft += 1;
  16. box.style.left = posLeft+'px';
  17. }
  18. }
  19. function cac() {
  20. if(posLeft >= 150 && posTop >= 0) {
  21. posTop -= 1;
  22. box.style.bottom = posTop+'px';
  23.  
  24. }
  25. else if(posTop == 0) {
  26. clearInterval(moveDown);
  27. }
  28. }
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement