Fixed NULL reference exceptions on joycon switching.

This commit is contained in:
Chris 2018-01-13 22:46:12 -05:00
parent 071715207e
commit a1808243a6

View File

@ -1,8 +1,9 @@
// Hero navbar fades to the normal navbar color once scrolled.
const navbar = document.getElementById('hero-navbar'); const navbar = document.getElementById('hero-navbar');
const navbarBaseColor = 'is-dark'; const navbarBaseColor = 'is-dark';
if (navbar) { if (navbar) {
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {
if (window.scrollY > 0) { if (window.scrollY > 0) {
navbar.classList.add('is-freestanding'); navbar.classList.add('is-freestanding');
navbar.classList.add(navbarBaseColor); navbar.classList.add(navbarBaseColor);
@ -14,6 +15,14 @@ if (navbar) {
} }
// Handle random switch colors // Handle random switch colors
const colors = ["orangered", "deepskyblue", "yellow", "deeppink", "lime", "gray"]; const leftJoycon = document.getElementById('LeftJoy');
document.getElementById('LeftJoy').classList.add("switch-" + colors[Math.floor(Math.random() * colors.length)]); const rightJoycon = document.getElementById('RightJoy');
document.getElementById('RightJoy').classList.add("switch-" + colors[Math.floor(Math.random() * colors.length)]); const colors = ['orangered', 'deepskyblue', 'yellow', 'deeppink', 'lime', 'gray'];
if (leftJoycon) {
leftJoycon.classList.add('switch-' + colors[Math.floor(Math.random() * colors.length)]);
}
if (rightJoycon) {
rightJoycon.classList.add('switch-' + colors[Math.floor(Math.random() * colors.length)]);
}