Skip to content

Commit

Permalink
update background video and clock logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenfromVN committed Dec 16, 2023
1 parent bf42bc4 commit 605a8f2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ async function setUpStaticResources() {
if (item.imgSrc === 'neon-background') {
const videoElement = document.getElementById('background-image');
videoElement.src = blobUrl;
videoElement.play();
}
item.imgSrc = blobUrl;
});
Expand Down Expand Up @@ -1222,15 +1221,26 @@ function startClock() {
const time = dateObj.getTime();
const nextTime = Math.floor((time + 1000) / 1000) * 1000;
const delay = nextTime - time;
updateTime(dateObj);
setTimeout(tick, delay);
updateTime(dateObj);
}
tick();
}

function setUpBackground() {
async function setUpBackground() {
const element = document.getElementById('background-image');
element.play();
const getVideoReady = new Promise((resolve) => {
function check() {
const videoHeight = element.offsetHeight;
if (videoHeight > 200) {
return resolve();
}
return setTimeout(check);
}
check();
});
await getVideoReady;
element.style.top = '0px';
element.style.left = '0px';
const backgroundWidth = element.offsetWidth;
Expand Down Expand Up @@ -1279,7 +1289,7 @@ async function init() {
alertText.style.transition = 'opacity 0.5s';
const loadingScreen = document.getElementById('loading');
loadingScreen.addEventListener('click', async () => {
setUpBackground();
await setUpBackground();
prepareMusic();
await requireGeoInfo();
startWeatherWidget();
Expand Down

0 comments on commit 605a8f2

Please sign in to comment.