-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
42 lines (38 loc) · 1.11 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
(function() {
const photoSwitches = document.querySelectorAll('.aboutme-photo-switch');
let activeSwitch = 1;
const profileImgs = document.querySelectorAll('.aboutme-photo-img');
let timeout;
/**
* manages timout for switching to next profile pic
*/
function scheduleNextChange() {
clearTimeout(timeout);
timeout = setTimeout(() => {
switchProfilePic((activeSwitch + 1) % 3);
}, 5000);
}
/**
* switches to selected profile pic and schedules next change event
*
* @param index index of profile pic to show
*/
function switchProfilePic(index) {
photoSwitches[activeSwitch].classList.remove('active');
profileImgs[activeSwitch].classList.remove('active');
photoSwitches[index].classList.add('active');
profileImgs[index].classList.add('active');
activeSwitch = index;
scheduleNextChange();
}
/**
* sets event listeners on switches to let user choose a profile pic
*/
photoSwitches.forEach((_switch, index) => {
_switch.addEventListener('click', () => {
switchProfilePic(index);
});
});
scheduleNextChange();
})();