Skip to content

Instantly share code, notes, and snippets.

@ahkohd
Last active April 9, 2020 09:58
Show Gist options
  • Save ahkohd/66945b7dc857c019db9b5164e2ecd4f7 to your computer and use it in GitHub Desktop.
Save ahkohd/66945b7dc857c019db9b5164e2ecd4f7 to your computer and use it in GitHub Desktop.
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