weferfw

loading screen ♡

Jan 24th, 2026
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.40 KB | None | 0 0
  1. <!--
  2. FULLSCREEN LOADING SCREEN SETUP
  3. ──────────────────────────────
  4. ♡ the HTML can be placed anywhere inside the <body>
  5. ♡ the <script> should be placed before </body>
  6. ♡ the CSS should go in your main stylesheet or inside a <style> tag
  7. -->
  8.  
  9. <!-- =========================
  10.     LOADER HTML
  11.     =========================
  12. change the src to the link of your image
  13. (works as gifs or png, you can choose)
  14. -->
  15.  
  16. <div id="loader-wrapper">
  17.     <img src="/your-image.gif" alt="loading...">
  18. </div>
  19.  
  20. <!-- =========================
  21.     LOADER JAVASCRIPT
  22.     =========================
  23. this script controls when the loader appears and disappears.
  24.  
  25. BEHAVIOR:
  26. ♡ waits for the loader image to be ready
  27. ♡ shows the loader as soon as the image is loaded
  28. ♡ keeps it visible until the entire page finishes loading
  29. ♡ after page load:
  30.  - waits 1.5 seconds
  31.  - fades the loader out over 1 second
  32.  
  33. IMPORTANT:
  34. ♡ you can change the value from 1500 to:
  35. - 1000 (disappears faster)
  36. - 3000 (stays longer)
  37. or just mess with the numbers until you're happy :3
  38. -->
  39.  
  40. <script>
  41. const loader = document.getElementById('loader-wrapper');
  42. const img = loader.querySelector('img');
  43. const body = document.body;
  44.  
  45. function showLoader() {
  46.     loader.classList.add('active');
  47.     body.classList.add('loading');
  48. }
  49.  
  50. if (img.complete) {
  51.     showLoader();
  52. } else {
  53.     img.addEventListener('load', showLoader);
  54. }
  55.  
  56. window.addEventListener('load', function() {
  57.     setTimeout(() => {
  58.         loader.classList.remove('active');
  59.         setTimeout(() => {
  60.             body.classList.remove('loading');
  61.         }, 1000);
  62.     }, 1500);
  63. });
  64. </script>
  65.  
  66. <!-- =========================
  67.     LOADER CSS
  68.     =========================
  69. this CSS makes the loader:
  70. ♡ fixed to the viewport
  71. ♡ full width and height
  72. ♡ sit above all content
  73. ♡ fade in and out smoothly
  74. -->
  75.  
  76. <style>
  77. #loader-wrapper {
  78.     position: fixed;
  79.     top: 0;
  80.     left: 0;
  81.     width: 100vw;
  82.     height: 100vh;
  83.     background: #000;
  84.     z-index: 9999999;
  85.     opacity: 0;
  86.     transition: opacity 1s ease-in-out;
  87.     pointer-events: none;
  88.     display: block;
  89. }
  90.  
  91. #loader-wrapper.active {
  92.     opacity: 1;
  93.     pointer-events: auto;
  94. }
  95.  
  96. #loader-wrapper img {
  97.     width: 100%;
  98.     height: 100%;
  99.     object-fit: cover;
  100. }
  101. </style>
  102.  
  103. <!--
  104. not created by me!
  105. have fun~ :3
  106. -->
  107.  
Advertisement
Add Comment
Please, Sign In to add comment