Summary Files Commits Branches @commit @diff @stats
path: root / src / scripts / snow.js
blob: 54d581b483d31af8a00a32698270236da3706e9b (plain) (blame)
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
if (enableSnow) {
	// Parameters

	const snowflakes = 80;

	// Add snowflakes

	function randInt(min, max) {
		return Math.floor(Math.random() * (max - min + 1) ) + min;
	}

	for (let snowflakeI = 0; snowflakeI < snowflakes; snowflakeI++) {
		const snowflake = document.createElement('div');
		snowflake.classList.add(
			'snowflake',
			'snow-column-' + ((snowflakeI % 20) + 1),
			'snow-start-'  + randInt(1, 20),
			'snow-speed-'  + randInt(1, 9));
		snowCont.appendChild(snowflake);
	}

	// Snowflake button

	snowBtn.onclick = function() {
		snowCont.classList.toggle('noSnow');

		if (localStorage.getItem('snow') !== 'off') {
			localStorage.setItem('snow', 'off');
			snowEnabledLabel.innerText = 'Add';
		}
		else {
			localStorage.setItem('snow', 'on');
			snowEnabledLabel.innerText = 'Remove';
		}
	}
}