-
Notifications
You must be signed in to change notification settings - Fork 0
/
preloader.js
50 lines (45 loc) · 1.59 KB
/
preloader.js
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Create the overlay and SVG elements
const overlay = document.createElement('div');
overlay.id = 'loader';
overlay.style.cssText = `
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.7);
z-index: 999;
`;
const svgImage = document.createElement('img');
svgImage.id = 'svgImage';
svgImage.src = 'https://cdn.jsdelivr.net/gh/tstomtimes/flutter_preloader@main/preload.svg';
svgImage.style.cssText = `
max-width: 100%;
max-height: 100%;
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
`;
svgImage.style.display = 'none';
// Append the elements to the body
document.body.appendChild(overlay);
document.body.appendChild(svgImage);
// Function to hide the overlay and display the SVG
function hideOverlay() {
overlay.style.display = 'none';
svgImage.style.display = 'block';
}
// Add an event listener to hide the overlay when all external JS files are loaded
document.addEventListener('DOMContentLoaded', () => {
// Replace the following lines with the actual code that loads your external JS files
// For demonstration purposes, we'll use a setTimeout to simulate loading external JS files.
setTimeout(hideOverlay, 100); // Replace with your actual loading code.
});
// Fallback: If all external resources are loaded and the DOMContentLoaded event doesn't fire,
// we'll still hide the overlay when the window's load event is triggered.
window.addEventListener('load', hideOverlay);