Optimize progress bar
This commit is contained in:
parent
30b6644f21
commit
73a193d602
3 changed files with 21 additions and 5 deletions
|
|
@ -114,8 +114,8 @@ export function renderSidebar (content) {
|
|||
* render loading bar
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function renderLoading ({ loaded, total }) {
|
||||
const num = Math.floor(loaded / total * 100)
|
||||
export function renderLoading ({ loaded, total, step }) {
|
||||
let num
|
||||
|
||||
if (!CACHE.loading) {
|
||||
const div = document.createElement('div')
|
||||
|
|
@ -124,13 +124,19 @@ export function renderLoading ({ loaded, total }) {
|
|||
document.body.appendChild(div)
|
||||
CACHE.loading = div
|
||||
}
|
||||
if (step) {
|
||||
num = parseInt(CACHE.loading.style.width, 10) + step
|
||||
num = num > 80 ? 80 : num
|
||||
} else {
|
||||
num = Math.floor(loaded / total * 100)
|
||||
}
|
||||
|
||||
CACHE.loading.style.opacity = 1
|
||||
CACHE.loading.style.width = num >= 95 ? '100%' : num + '%'
|
||||
|
||||
if (num >= 95) {
|
||||
clearTimeout(renderLoading.cacheTImeout)
|
||||
renderLoading.cacheTImeout = setTimeout(_ => {
|
||||
clearTimeout(renderLoading.cacheTimeout)
|
||||
renderLoading.cacheTimeout = setTimeout(_ => {
|
||||
CACHE.loading.style.opacity = 0
|
||||
CACHE.loading.style.width = '0%'
|
||||
}, 200)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue