Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 27, 2019 22:06
Show Gist options
  • Save ilearnjavascript/47436e9bace99336d47b73f3417134eb to your computer and use it in GitHub Desktop.
Save ilearnjavascript/47436e9bace99336d47b73f3417134eb to your computer and use it in GitHub Desktop.
fadein - 2.js
const fadeIn = (el, smooth = true, displayStyle = 'block') => {
el.style.opacity = 0;
el.style.display = displayStyle;
if (smooth) {
let opacity = 0;
let request;
const animation = () => {
el.style.opacity = opacity += 0.04;
if (opacity >= 1) {
opacity = 1;
cancelAnimationFrame(request);
}
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment