Skip to content

Instantly share code, notes, and snippets.

@0x4248
Created April 25, 2022 18:42
Show Gist options
  • Save 0x4248/8a4ea5996b2ba25b99abcd55974a7281 to your computer and use it in GitHub Desktop.
Save 0x4248/8a4ea5996b2ba25b99abcd55974a7281 to your computer and use it in GitHub Desktop.
JS opacity animator
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function opacity_to_100(id){
var opacity = 0
for (let i = 0; i < 25; i++) {
document.getElementById(id).style.opacity = opacity+"%"
opacity = opacity + 4
await sleep(10)
}
}
async function opacity_to_0(id){
var opacity = 100
for (let i = 0; i < 25; i++) {
document.getElementById(id).style.opacity = opacity+"%"
opacity = opacity - 4
await sleep(10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment