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 navbarBaseColor = 'is-dark';
if (navbar) {
window.addEventListener('scroll', () => {
window.addEventListener('scroll', () => {
if (window.scrollY > 0) {
navbar.classList.add('is-freestanding');
navbar.classList.add(navbarBaseColor);
@ -14,6 +15,14 @@ if (navbar) {
}
// Handle random switch colors
const colors = ["orangered", "deepskyblue", "yellow", "deeppink", "lime", "gray"];
document.getElementById('LeftJoy').classList.add("switch-" + colors[Math.floor(Math.random() * colors.length)]);
document.getElementById('RightJoy').classList.add("switch-" + colors[Math.floor(Math.random() * colors.length)]);
const leftJoycon = document.getElementById('LeftJoy');
const rightJoycon = document.getElementById('RightJoy');
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)]);
}