Created
October 16, 2017 12:53
-
-
Save h1ldebrand/6ac9d5e9579fb24a68c762aeb4826e8e to your computer and use it in GitHub Desktop.
my own function fadeOut on Vanilla.js
This file contains hidden or 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 fadeOut(selector, time){ | |
let timer = time || 400; | |
let element = document.querySelectorAll(selector)[0]; | |
let timeForSetInterver = 20; | |
let opacityStart = getComputedStyle(element).opacity; | |
let count = timer / timeForSetInterver; | |
let step = opacityStart / 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 = 0; | |
} | |
}, timeForSetInterver) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much, I was looking for something like that.