Skip to content

Instantly share code, notes, and snippets.

@h1ldebrand
Last active October 16, 2017 12:50
Show Gist options
  • Save h1ldebrand/7c10f874529aac1477150576519f459a to your computer and use it in GitHub Desktop.
Save h1ldebrand/7c10f874529aac1477150576519f459a to your computer and use it in GitHub Desktop.
My own function fadeIn on Vanilla.js
function fadeIn(selector, time){
let timer = time || 400;
let element = document.querySelectorAll(selector)[0];
let timeForSetInterver = 20;
let opacityEnd = 1;
let count = timer / timeForSetInterver;
let step = opacityEnd / count;
let i = 0;
let forClear = setInterval(function(){
let opacity = getComputedStyle(element).opacity;
element.style.opacity = parseFloat(opacity) + parseFloat(step);
i++;
if(i == count){
clearInterval(forClear);
element.style.opacity = 1
}
}, timeForSetInterver)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment