Skip to content

Commit 84f4a44

Browse files
committed
feat(template js): add pregress line based on config
1 parent ce30ed8 commit 84f4a44

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

template/src/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.getElementsByTagName('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)';
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)