JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body>
<div id="video-id" onclick="inc()"></div>
<img loading="lazy" src="" />
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
</body>
</html>
<!--
1. Focus on the image pane by clicking on it once.
2. Use the ←left and right→ arrow keys to change image ids.
-->
CSS
body {
background: #fff;
}
img {
max-width: 100%;
z-index: 0;
}
#video-id {
position: fixed;
width: 100px;
font-size: 24pt;
top: 5;
right: 0;
cursor: pointer;
}
.lds-ring.hidden {
display: none;
}
.lds-ring {
display: block;
position: fixed;
width: 32px;
height: 32px;
padding-top: 5px;
padding-left: 5px;
top: 0;
left: 0;
z-index: 1;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 32px;
height: 32px;
margin: 8px;
border: 8px solid #fff;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #000 transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
JavaScript
img = document.querySelector('img')
lds = document.querySelector('div.lds-ring')
n = 10710
img.src = `https://image.check.tv/lives/${n}/vertical.jpg`
id = document.querySelector('#video-id')
id.innerHTML = n
img.addEventListener('error', () => {
console.log('error')
lds.classList.add('hidden')
})
img.addEventListener('load', () => {
console.log('load')
lds.classList.add('hidden')
})
function render() {
url = `https://image.check.tv/lives/${n}/vertical.jpg`
img.src = url
id.innerHTML = n
lds.classList.remove('hidden')
}
function inc() { n++; render() }
function dec() { n--; render() }
document.body.addEventListener('keydown', (ev) => {
switch (ev.code) {
case 'ArrowLeft':
dec()
break;
case 'ArrowRight':
inc()
break
}
})