Last active
April 9, 2020 09:58
-
-
Save ahkohd/66945b7dc857c019db9b5164e2ecd4f7 to your computer and use it in GitHub Desktop.
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
const fadeWindowIn = ( | |
browserWindowToFadeIn, | |
step = 0.1, | |
fadeEveryXSeconds = 10 | |
) => { | |
// Get the opacity of the window. | |
let opacity = browserWindowToFadeIn.getOpacity(); | |
// Increase the opacity of the window by `step` every `fadeEveryXSeconds` | |
// seconds. | |
const interval = setInterval(() => { | |
// Stop fading if window's opacity is 1 or greater. | |
if (opacity >= 1) window.clearInterval(interval); | |
browserWindowToFadeIn.setOpacity(opacity); | |
opacity += step; | |
}, fadeEveryXSeconds); | |
// Return the interval. Useful if we want to stop fading at will. | |
return interval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment