Skip to content

Commit d17e4a6

Browse files
Merge pull request #1 from nextbitlabs/feat/line-progress
Add progress line
2 parents ce30ed8 + e5db10f commit d17e4a6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

template/onepunch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"width": 960,
3-
"height": 600
3+
"height": 600,
4+
"progress": "line"
45
}

template/src/index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Get configuration parameters and initialize the web page;
2+
Get configuration parameters and initialize the web page;
33
*/
44

55
(async function () {
@@ -15,6 +15,7 @@ Get configuration parameters and initialize the web page;
1515
function init(config) {
1616
addEventListeners(config);
1717
setBorders(config.width, config.height);
18+
addProgress(config);
1819
}
1920

2021
/*
@@ -67,3 +68,35 @@ function handleOnkeydown(event) {
6768
// No default
6869
}
6970
}
71+
72+
/*
73+
Add progress to each slide based on config
74+
*/
75+
76+
function addProgress(config) {
77+
if(!config.progress || config.progress === 'none') {
78+
return;
79+
}
80+
81+
const articles = [...document.querySelectorAll()('main > article')];
82+
83+
if(config.progress === 'line') {
84+
articles.forEach((article, index) => {
85+
const line = document.createElement('div');
86+
line.classList.add("progress-line");
87+
article.appendChild(line);
88+
89+
line.style.backgroundColor = 'var(--primary-color, #000)';
90+
91+
line.style.height = '3px';
92+
line.style.position = 'absolute';
93+
94+
line.style.bottom = '0';
95+
line.style.left = '0';
96+
97+
const normIndex = index / (articles.length - 1);
98+
99+
line.style.width = `${config.width * normIndex}px`;
100+
})
101+
}
102+
}

0 commit comments

Comments
 (0)