Guest User

Untitled

a guest
Jan 20th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function colorAndWait (f, delay, color) {
  2. return function() {
  3. f.style.backgroundColor = color;
  4. return new Promise(resolve => {
  5. setTimeout(function() {
  6. console.log('before resolve', delay, color);
  7. resolve();
  8. },delay);
  9. });
  10. }
  11. }
  12.  
  13. function change() {
  14. var f = document.getElementById('square');
  15. return new Promise((resolve, reject) => {
  16. setTimeout(() => {
  17. return resolve();
  18. }, 500);
  19. })
  20. .then(colorAndWait(f, 500, 'blue'))
  21. .then(colorAndWait(f, 500, 'white'))
  22. .then(colorAndWait(f, 500, 'blue'))
  23. .then(colorAndWait(f, 500, 'white'));
  24.  
  25. // var f = document.getElementById('square');
  26. // setTimeout(function blink() {
  27. // f.style.backgroundColor = 'blue';
  28. // setTimeout(function blink() {
  29. // f.style.backgroundColor = 'white';
  30. // setTimeout(function blink() {
  31. // f.style.backgroundColor = 'blue';
  32. // setTimeout(function blink() {
  33. // f.style.backgroundColor = 'white';
  34. // },500);
  35. // },500);
  36. // },500);
  37. // },500);
  38. }
Add Comment
Please, Sign In to add comment