Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ With :

`containerClass` must be used to override the `.progress-bar-container--container` default class. You can use the default `:class` syntax on the component to add classes if needed.

## Methods

| key | description | type |function property|
|:--------|-------------------------|--------|-----------------|
|`onClick`|When clicked on scrollbar|Function| event object |

## Events

|key|description|
|:---|---|
| `begin`|When scroll reached 0%|
|`complete`|When scroll reached 100%|
| key | event condition | return value |
|:---------|---------------------|-------------------------|
| `begin` | Scroll reached 0% | – |
|`complete`| Scroll reached 100% | – |
|`update` | Every scroll event | Scroll position (0-100) |

## Develop

Expand Down
18 changes: 18 additions & 0 deletions src/components/VueScrollProgressBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
background: containerColor,
zIndex: zIndex
}"
@click="onClick($event)"
>
<div
:class="barClass"
Expand Down Expand Up @@ -54,6 +55,11 @@ export default {
'progress-bar-container--container': true
}
}
},

onClick: {
type: Function,
default: () => {}
}
},

Expand All @@ -69,6 +75,10 @@ export default {
this.width = (window.scrollY / height) * 100
const eventWidth = Math.ceil(this.width)

if (this.emitUpdate) {
this.$emit("update", eventWidth)
}

if (eventWidth === 0) {
this.$emit("begin")
}
Expand All @@ -79,12 +89,20 @@ export default {
}
},

computed: {
emitUpdate () {
return Object.keys(this.$listeners).includes('update')
}
},

mounted() {
window.addEventListener("resize", this.handleScroll)
window.addEventListener("scroll", this.handleScroll)
window.dispatchEvent(new Event("scroll"))
},

destroyed() {
window.addEventListener("resize", this.handleScroll)
window.removeEventListener("scroll", this.handleScroll)
}
}
Expand Down