Created
June 21, 2022 21:49
-
-
Save robshep/5f42b8b7f2b222d39ce4f705ba4d362e to your computer and use it in GitHub Desktop.
Load data from API and display on web page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html style="padding: 0; margin: 0;"> | |
<head> | |
<meta charset="UTF-8" /> | |
<style> | |
body, html { | |
margin:0; | |
padding:0; | |
} | |
div#bg { | |
position:absolute; | |
top:0; | |
left:0; | |
right:0; | |
bottom:0; | |
background-image: url(https://unsplash.com/photos/RLw-UC03Gwc/download?ixid=MnwxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNjU1ODQ3Nzcw&force=true&w=2400); | |
background-size: cover; | |
background-position: center; | |
} | |
div#statsbox { | |
position: fixed; | |
bottom: 0px; | |
right: 0px; | |
width: 250px; | |
height: 50px; | |
padding: 3px; | |
background-color: beige; | |
margin: 5px; | |
padding: 5px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="bg"> | |
<div id="statsbox">LOADING ...</div> | |
</div> | |
<script> | |
function fetchAndShow() { | |
fetch('https://dummyjson.com/todos/random') | |
.then(res => res.json()) | |
.then(data => { | |
document.getElementById("statsbox").innerHTML = "todo: " + data.todo | |
}); | |
} | |
setInterval(fetchAndShow, 3500); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment