loader.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const spinner = {
  2. interval:80,
  3. frames:[
  4. "[        ]",
  5. "[=       ]",
  6. "[==      ]",
  7. "[===     ]",
  8. "[====    ]",
  9. "[=====   ]",
  10. "[ =====  ]",
  11. "[  ===== ]",
  12. "[   =====]",
  13. "[    ====]",
  14. "[     ===]",
  15. "[      ==]",
  16. "[       =]",
  17. "[        ]",
  18. "[       =]",
  19. "[      ==]",
  20. "[     ===]",
  21. "[    ====]",
  22. "[   =====]",
  23. "[  ===== ]",
  24. "[ =====  ]",
  25. "[=====   ]",
  26. "[====    ]",
  27. "[===     ]",
  28. "[==      ]",
  29. "[=       ]"]
  30. }
  31. function loader() {
  32. const grid = document.getElementById('loader')
  33. const spin = document.createElement('div');
  34. spin.innerText = spinner.frames[0];
  35. grid.appendChild(spin);
  36. let i = 0;
  37. return setInterval(() => {
  38. requestAnimationFrame(() => {
  39. spin.innerHTML = spinner.frames[++i % spinner.frames.length];
  40. });
  41. }, spinner.interval);
  42. }