Merge pull request #1 from CTEC3905-2022/rememberBG

Added code to remember the last background color and load it on page …
This commit is contained in:
Notoric 2024-03-08 16:06:32 +00:00 committed by GitHub
commit d1168d1aa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -88,6 +88,7 @@ bgColour.addEventListener("input", () => {
const G = parseInt(bgColour.value.substring(3, 5), 16);
const B = parseInt(bgColour.value.substring(5, 7), 16);
changeBackground(R, G, B);
localStorage.setItem("bgColour", bgColour.value);
});
function transitionBackground(newUrl, blackwhite) {
@ -202,7 +203,13 @@ function initCarousel() {
}
// INITIALIZATION
transitionBackground("assets/photos/fog-8519076-nordseher.jpg", "black")
// Set background colour to last saved value
const bgColor = document.getElementById("bgColour");
bgColor.value = localStorage.getItem("bgColour") || "#ffffff";
const initR = parseInt(bgColour.value.substring(1, 3), 16);
const initG = parseInt(bgColour.value.substring(3, 5), 16);
const initB = parseInt(bgColour.value.substring(5, 7), 16);
changeBackground(initR, initG, initB);
// Initialize carousel
initCarousel();
carouselExpand(1);