Last active
October 16, 2017 12:50
-
-
Save h1ldebrand/7c10f874529aac1477150576519f459a to your computer and use it in GitHub Desktop.
My own function fadeIn on Vanilla.js
This file contains 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
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