loading-screen.js 836 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export class loading_screen {
  2. static #instance;
  3. #screen;
  4. constructor(classname = "loading-screen") {
  5. if (!loading_screen.#instance) {
  6. loading_screen.#instance = this;
  7. this.#init(classname);
  8. }
  9. return loading_screen.#instance;
  10. }
  11. get time() {
  12. return 400;
  13. }
  14. #init(classname) {
  15. this.#screen = document.querySelector(`.${classname}`);
  16. this.#screen.style.transitionDuration = `${this.time / 1000}s`;
  17. this.show();
  18. }
  19. get visible() {
  20. return !this.#screen.classList.contains("hidden");
  21. }
  22. show() {
  23. if (!this.visible) {
  24. this.#screen.classList.remove("hidden");
  25. }
  26. }
  27. hide() {
  28. if (this.visible) {
  29. this.#screen.classList.add("hidden");
  30. }
  31. }
  32. }