JavaScript Loading Page

 


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading Page</title>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #ffffff;
color: #0039d7;
font-family: Arial, sans-serif;
}

.loader {
text-align: center;
}

.progress-bar {
width: 800px;
height: 40px;
background-color: #ffffff;
border-radius: 20px;
margin-top: 20px;
box-shadow: inset 0 0 10px #000000;
}

.progress-fill {
height: 40px;
width: 0%;
background-color: #4caf50;
border-radius: 20px;
transition: width 0.2s;
}

.percentage {
font-size: 34px;
margin-top: 10px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="loader">
<div class="percentage">0%</div>
<div class="progress-bar">
<div class="progress-fill"></div>
</div>
</div>
<script>
const percentageText = document.querySelector('.percentage');
const progressFill = document.querySelector('.progress-fill');

let progress = 0;

// Simulate loading process
const interval = setInterval(() => {
if (progress >= 100) {
clearInterval(interval);
// Optionally, navigate to a new page or hide the loader
setTimeout(() => {
// Redirect to a page when loading 100%
window.location.href = "main-page.html";
}, 500);
} else {
progress += 1;
percentageText.textContent = `${progress}%`;
progressFill.style.width = `${progress}%`;
}
}, 50); // Adjust the speed here (50ms for smooth update)
</script>
</body>
</html>

Comments

Popular posts from this blog

ការសរសេរ JavaScript ចូលក្នុង Web Page

Create Pop up Form in JavaScript

ការប្រើ Switch ក្នុង JavaScript