Simplify calcBackground

This commit is contained in:
Neil Brommer 2017-12-31 15:52:48 -08:00
parent 61f9136a03
commit 6628e2c89c

View file

@ -1,6 +1,14 @@
// use this when making changes so that there is no need to parse the page // use this when making changes so that there is no need to parse the page
var backgroundList = ["img/1.png", "img/2.png", "img/3.png", "img/4.png", var backgroundList = [
"img/5.png", "img/6.png", "img/7.png", "img/8.png"]; {address: "img/1.png", dark: false},
{address: "img/2.png", dark: false},
{address: "img/3.png", dark: false},
{address: "img/4.png", dark: false},
{address: "img/5.png", dark: false},
{address: "img/6.png", dark: true},
{address: "img/7.png", dark: true},
{address: "img/8.png", dark: true}
];
$(document).ready(function () { $(document).ready(function () {
calcBackground(); calcBackground();
@ -14,30 +22,16 @@ function calcBackground() {
var mins = now.getMinutes(); var mins = now.getMinutes();
var total = (hours * 60) + mins; var total = (hours * 60) + mins;
// 24*60 = 1440 var period = (24 / backgroundList.length) * 60; // in minutes
// 2:40 between each step
if (total > 300 && total < 460) // 5:00 - 7:40 var background = backgroundList[Math.floor(total / period)];
setBackground(0, false); setBackground(background.address, background.dark);
else if (total > 460 && total < 620)
setBackground(1, false);
else if (total > 620 && total < 780)
setBackground(2, false);
else if (total > 780 && total < 940)
setBackground(3, false);
else if (total > 940 && total < 1100)
setBackground(4, false);
else if (total > 1100 && total < 1260)
setBackground(5, true);
else if (total > 1260 && total < 1420)
setBackground(6, true);
else
setBackground(7, true);
} }
} }
function setBackground(num, dark) { function setBackground(address, dark) {
// dark is a boolean that indicates the brightness of the background // dark is a boolean that indicates the brightness of the background
$("body").css("background-image", "url(" + backgroundList[num] + ")"); $("body").css("background-image", "url(" + address + ")");
if (dark) { if (dark) {
$(".navbar").removeClass("navbar-dark").addClass("navbar-light"); $(".navbar").removeClass("navbar-dark").addClass("navbar-light");