Skip to content

Instantly share code, notes, and snippets.

@ahkohd
Created April 9, 2020 09:49
Show Gist options
  • Save ahkohd/94cd831051b14782b093abf7f4f38ee8 to your computer and use it in GitHub Desktop.
Save ahkohd/94cd831051b14782b093abf7f4f38ee8 to your computer and use it in GitHub Desktop.
const fadeWindowOut = (
browserWindowToFadeOut,
step = 0.1,
fadeEveryXSeconds = 10
) => {
// Get the opacity of the window.
let opacity = browserWindowToFadeOut.getOpacity();
// Reduce the opacity of the window by `step` every `fadeEveryXSeconds`.
// seconds.
const interval = setInterval(() => {
// Stop fading if window's opacity is 0 or lesser.
if (opacity <= 0) window.clearInterval(interval);
browserWindowToFadeOut.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