Skip to content

Commit

Permalink
new: added progress bar animation (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtushar11 authored Oct 15, 2022
1 parent ae52eed commit 749e3a9
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ProgressBar/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Progress bar</title>
</head>
<body>
<h2>Progressing</h2>
<div class="container">
<div class="progress">
<div class="progress-bar" data-complete="0">10%</div>
</div>
</div>

<div class="btn-container">
<button class="btn start" type="button">Start Progress</button>
</div>
<script src="index.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions ProgressBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const progressBar = document.querySelector(".progress-bar");
let progressComplete = progressBar.getAttribute("data-complete");
const start = document.querySelector(".start");
const reset = document.querySelector(".reset");

start.addEventListener("click", clickEvent);
reset.addEventListener("click", function() {
progressBar.style.opacity = "10";
});

function clickEvent() {
let width = 10;
progressComplete = 100;

const count = setInterval(() => {
if (width != progressComplete) {
width++;
progressBar.style.opacity = "10";
progressBar.style.width = width + "%";
progressBar.innerHTML = width + "%";
} else {
clearInterval(count);
}
}, 10);
}
114 changes: 114 additions & 0 deletions ProgressBar/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@import url("https://fonts.googleapis.com/css?family=PT+Sans&display=swap");

* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-family: monospace;
}

/* CSS Variables */
:root {
--primary-color: #256D85;
--secondary-color: #2B4865;
--light-color: #f4f4f4;
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
font-family: "PT Sans", sans-serif;
font-weight: 600;
line-height: 1.6;
}
h2{
margin-bottom: 20px;
}
.container {
height: 3rem;
width: 600px;
margin-bottom: 3rem;
background-color: var(--light-color);
border-radius: 10rem;
}

.progress {
height: 3rem;
width: 100%;
border-radius: 10rem;
}

.progress-bar {

width: 10%;
height: 30px;
background-color: #256D85;
text-align: center; /* To center it horizontally (if you want) */
line-height: 30px; /* To center it vertically */
color: white;
border-radius: 10rem;
height: 3rem;
background: linear-gradient(to right,#533483, #002B5B);
color: var(--light-color);

}

.btn-container {
display: flex;
justify-content: center;
}

.btn {
flex: 1;
min-width: 50%;
padding: 1rem 2.5rem;
margin: 0 1rem;
background: linear-gradient(to left, #533483, #11998e);
color: var(--light-color);
border: none;
border-radius: 10rem;
outline: 0;
transition: transform 400ms;
box-shadow: 0 10px 10px 0 rgba(0, 0, 0, 0.3);
cursor: pointer;
}

.btn:hover {
transform: translateY(-10px);
}

.start {
background: linear-gradient(to right, #533483, #11998e);
}

.reset {
background: linear-gradient(to left, #533483, #11998e);
}

@media screen and (max-width: 900px) {
.container {
width: 500px;
}
}

@media screen and (max-width: 750px) {
.container {
width: 90%;
}

.btn {
margin: 0 15px;
width: 100%;
height: 36px;
line-height: 0.5;
}
}

0 comments on commit 749e3a9

Please sign in to comment.