Skip to content

Commit 28a1e6e

Browse files
Adding the main ScrollProgressBar component
1 parent 285b6f8 commit 28a1e6e

File tree

7 files changed

+98
-150
lines changed

7 files changed

+98
-150
lines changed

src/App.vue

-28
This file was deleted.

src/assets/logo.png

-6.69 KB
Binary file not shown.

src/components/HelloWorld.vue

-114
This file was deleted.
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<template>
2+
<div
3+
class="progress-bar-container--container"
4+
:style="{ background: containerColor }"
5+
>
6+
<div
7+
:style="{
8+
width: `${width}%`,
9+
height: height,
10+
background: backgroundColor
11+
}"
12+
></div>
13+
</div>
14+
</template>
15+
16+
<script>
17+
export default {
18+
name: "VueScrollProgressBar",
19+
20+
props: {
21+
height: {
22+
type: String,
23+
default: ".5rem"
24+
},
25+
26+
backgroundColor: {
27+
type: String,
28+
default: "linear-gradient(to right, #38C172, #51D88A)"
29+
},
30+
31+
containerColor: {
32+
type: String,
33+
default: "transparent"
34+
}
35+
},
36+
37+
data() {
38+
return {
39+
width: 0
40+
}
41+
},
42+
43+
methods: {
44+
handleScroll() {
45+
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight
46+
this.width = (window.scrollY / height) * 100
47+
const eventWidth = Math.ceil(this.width)
48+
49+
if (eventWidth === 0) {
50+
this.$emit("begin")
51+
}
52+
53+
if (eventWidth === 100) {
54+
this.$emit("complete")
55+
}
56+
}
57+
},
58+
59+
mounted() {
60+
window.addEventListener("scroll", this.handleScroll)
61+
window.dispatchEvent(new Event("scroll"))
62+
},
63+
64+
destroyed() {
65+
window.removeEventListener("scroll", this.handleScroll)
66+
}
67+
}
68+
</script>
69+
70+
<style scoped>
71+
.progress-bar-container--container {
72+
position: fixed;
73+
width: 100%;
74+
top: 0;
75+
left: 0;
76+
}
77+
</style>

src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import VueScrollProgressBar from "./components/VueScrollProgressBar";
2+
3+
const install = function(Vue) {
4+
Vue.component(VueScrollProgressBar.name, VueScrollProgressBar);
5+
};
6+
7+
if (typeof window !== "undefined" && window.Vue) {
8+
window.VueScrollProgressBar = VueScrollProgressBar;
9+
window.Vue.use(VueScrollProgressBar);
10+
}
11+
12+
VueScrollProgressBar.install = install;
13+
export default VueScrollProgressBar;
14+
export { VueScrollProgressBar };

src/main.js

-8
This file was deleted.

vue.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
pages: {
3+
index: {
4+
entry: "src/index.js"
5+
}
6+
}
7+
};

0 commit comments

Comments
 (0)