Created
February 5, 2023 12:07
-
-
Save shivaji33/fa5b80511a8069c22e7a4d7f22fd0db6 to your computer and use it in GitHub Desktop.
Navi Frontend interview Question 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button onclick="add()">Add Progrss Bar</button> | |
<div id="root"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.progress { | |
margin: 1rem 0; | |
display: flex; | |
height: 1rem; | |
background: #e9ecef; | |
} | |
.progress-bar { | |
background: blue; | |
width: 0; | |
} | |
.w-100 { | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Navi interview question: queueable progress bars