added animated fading background

This commit is contained in:
Brandon4466
2024-05-07 13:06:21 -07:00
parent bd5845dd04
commit 49cd2b8735
3 changed files with 54 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" style="cursor: none;">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -7,6 +7,18 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.0/color-thief.umd.js"></script>
<style>
.animated-background {
transition: background-color 1s ease-in-out; /* add a transition effect */
background-color: #fff; /* initial background color */
}
.animated-background.update-color {
background-color: var(--color); /* change the background color to black */
}
@keyframes fade-in {
to {
background-color: var(--color); /* change the background color to black */
}
}
.progress-container {
position: fixed;
bottom: 8px;
@@ -81,7 +93,7 @@
}
</style>
</head>
<body>
<body class="animated-background">
<!-- <link href="http://127.0.0.1:8888/font" rel="stylesheet"> -->
<div class="total">
<div class="left">
@@ -174,8 +186,10 @@
document.getElementById('canvas_url').style.display = "none";
document.getElementById('image').style.display = "flex";
}
getColors(data['image'])
getLyrics(data['name'], data['artist'], data['progress_ms'], data['fetchlyrics'])
if (data['gofetch'] !== undefined) {
getColors(data['image'])
}
getLyrics(data['name'], data['artist'], data['progress_ms'], data['gofetch'])
}
});
}
@@ -200,8 +214,8 @@
}
});
}
function getLyrics(name, artist, progress_ms, fetchlyrics) {
if (lyrics == undefined || fetchlyrics !== undefined && name !== undefined) {
function getLyrics(name, artist, progress_ms, gofetch) {
if (lyrics == undefined || gofetch !== undefined && name !== undefined) {
$('#lyric').text('');
$.ajax({
url: '/lyrics',
@@ -229,15 +243,21 @@
const colorThief = new ColorThief();
const img = document.getElementById('image');
img.crossOrigin = 'Anonymous';
animatedBackground = document.querySelector('.animated-background');
if (img.complete) {
const color = colorThief.getColor(img);
document.body.style.backgroundColor = 'rgb(' + color + ')';
// document.body.style.backgroundColor = 'rgb(' + color + ')';
// document.body.style.backgroundColor = 'rgb(' + color + ')';
animatedBackground.style.setProperty('--color', 'rgb(' + color + ')');
animatedBackground.classList.add('update-color');
getLuminance(color);
} else {
img.addEventListener('load', function() {
const color = colorThief.getColor(img);
document.body.style.backgroundColor = 'rgb(' + color + ')';
// document.body.style.backgroundColor = 'rgb(' + color + ')';
animatedBackground.style.setProperty('--color', 'rgb(' + color + ')');
animatedBackground.classList.add('update-color');
getLuminance(color);
});
}