Skip to content

Commit

Permalink
fix: hide the progress bar on the case of backing forward
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 29, 2024
1 parent 4d7b504 commit ddc71d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/hb/modules/progress-bar/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Progress from "./progress";
(() => {
const progress = new Progress()

window.addEventListener('pagehide', () => {
progress.hide()
})

window.addEventListener('beforeunload', () => {
progress.show()
})
Expand Down
9 changes: 8 additions & 1 deletion assets/hb/modules/progress-bar/js/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ export default class Progress {
this.bar = bar
}

private timer = 0

show() {
this.ele.classList.remove('d-none')
setInterval(() => {
this.timer = setInterval(() => {
this.width += this.step
this.bar.style.width = `${this.width}%`
}, this.interval)
}

hide() {
this.ele.classList.add('d-none')
clearInterval(this.timer)
}
}

0 comments on commit ddc71d5

Please sign in to comment.