allaroundhere.org/js/custom.js

33 lines
1.3 KiB
JavaScript

// Some quick scripting to select a random background on page load
const BACKGROUND_IMAGES = [
"https://cdn.enp.one/img/backgrounds/cl-photo-allis.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-boston.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-denver.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-geese.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-hotel.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-lawrencedam.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-letchworth.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-library.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-lighthouse.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-mbta.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-rockyshore.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-rt112.jpg",
"https://cdn.enp.one/img/backgrounds/cl-photo-startrek.jpg",
];
function selectBackground() {
let max = BACKGROUND_IMAGES.length - 1
let min = 0;
index = Math.round(Math.random() * (max - min) + min);
console.log("Loading background #" + index + ": " + BACKGROUND_IMAGES[index]);
return BACKGROUND_IMAGES[index];
}
function setBackground() {
let ref = document.getElementById("background-image");
ref.style.backgroundImage = "url(" + selectBackground() + ")";
}