Skip to content

Instantly share code, notes, and snippets.

@shivaji33
Created February 5, 2023 12:07
Show Gist options
  • Save shivaji33/fa5b80511a8069c22e7a4d7f22fd0db6 to your computer and use it in GitHub Desktop.
Save shivaji33/fa5b80511a8069c22e7a4d7f22fd0db6 to your computer and use it in GitHub Desktop.
Navi Frontend interview Question 1
<button onclick="add()">Add Progrss Bar</button>
<div id="root"></div>
const root = document.getElementById("root");
const addProgressBar = (time = 3) => {
const progress = document.createElement("div");
const progressBar = document.createElement("div");
progress.classList.add("progress");
progressBar.classList.add("progress-bar");
const transition = `transition: width ${time}s ease`;
progressBar.style = transition;
progress.appendChild(progressBar);
root.appendChild(progress);
setTimeout(() => {
progressBar.classList.add("w-100");
}, 50);
progressBar.addEventListener("transitionend", () => {
count--;
if (count > 0) {
addProgressBar();
}
});
progressBar.removeEventListener("transitionend", () => {});
};
var count = 0;
const add = () => {
if (count === 0) {
addProgressBar();
}
count++;
};
.progress {
margin: 1rem 0;
display: flex;
height: 1rem;
background: #e9ecef;
}
.progress-bar {
background: blue;
width: 0;
}
.w-100 {
width: 100%;
}
@shivaji33
Copy link
Author

Navi interview question: queueable progress bars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment