Created
April 25, 2022 18:42
-
-
Save 0x4248/8a4ea5996b2ba25b99abcd55974a7281 to your computer and use it in GitHub Desktop.
JS opacity animator
This file contains 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
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