Optimize progress bar
This commit is contained in:
parent
30b6644f21
commit
73a193d602
3 changed files with 21 additions and 5 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 1.1.7
|
||||||
|
### Bug fixes
|
||||||
|
- Optimize progress bar
|
||||||
|
|
||||||
## 1.1.6
|
## 1.1.6
|
||||||
### Features
|
### Features
|
||||||
- Add logo 😂
|
- Add logo 😂
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,8 @@ export function renderSidebar (content) {
|
||||||
* render loading bar
|
* render loading bar
|
||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
export function renderLoading ({ loaded, total }) {
|
export function renderLoading ({ loaded, total, step }) {
|
||||||
const num = Math.floor(loaded / total * 100)
|
let num
|
||||||
|
|
||||||
if (!CACHE.loading) {
|
if (!CACHE.loading) {
|
||||||
const div = document.createElement('div')
|
const div = document.createElement('div')
|
||||||
|
|
@ -124,13 +124,19 @@ export function renderLoading ({ loaded, total }) {
|
||||||
document.body.appendChild(div)
|
document.body.appendChild(div)
|
||||||
CACHE.loading = 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.opacity = 1
|
||||||
CACHE.loading.style.width = num >= 95 ? '100%' : num + '%'
|
CACHE.loading.style.width = num >= 95 ? '100%' : num + '%'
|
||||||
|
|
||||||
if (num >= 95) {
|
if (num >= 95) {
|
||||||
clearTimeout(renderLoading.cacheTImeout)
|
clearTimeout(renderLoading.cacheTimeout)
|
||||||
renderLoading.cacheTImeout = setTimeout(_ => {
|
renderLoading.cacheTimeout = setTimeout(_ => {
|
||||||
CACHE.loading.style.opacity = 0
|
CACHE.loading.style.opacity = 0
|
||||||
CACHE.loading.style.width = '0%'
|
CACHE.loading.style.width = '0%'
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,14 @@ export function load (url, method = 'GET', loading) {
|
||||||
return {
|
return {
|
||||||
then: function (success, error = function () {}) {
|
then: function (success, error = function () {}) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
const id = setInterval(_ =>
|
||||||
|
loading({ step: Math.floor(Math.random() * 5 + 1) }),
|
||||||
|
500)
|
||||||
xhr.addEventListener('progress', loading)
|
xhr.addEventListener('progress', loading)
|
||||||
xhr.addEventListener('loaded', loading)
|
xhr.addEventListener('loadend', evt => {
|
||||||
|
loading(evt)
|
||||||
|
clearInterval(id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
xhr.addEventListener('error', error)
|
xhr.addEventListener('error', error)
|
||||||
xhr.addEventListener('load', ({ target }) => {
|
xhr.addEventListener('load', ({ target }) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue