Guest User

Untitled

a guest
Oct 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function fadeOut(selector, time){
  2.  
  3. let timer = time || 400;
  4. let element = document.querySelectorAll(selector)[0];
  5. let timeForSetInterver = 20;
  6. let opacityStart = getComputedStyle(element).opacity;
  7. let count = timer / timeForSetInterver;
  8. let step = opacityStart / count;
  9. let i = 0;
  10.  
  11. let forClear = setInterval(function(){
  12.  
  13. let opacity = getComputedStyle(element).opacity;
  14.  
  15. element.style.opacity = parseFloat(opacity) - parseFloat(step);
  16.  
  17. i++;
  18.  
  19. if(i == count){
  20. clearInterval(forClear);
  21. element.style.opacity = 0;
  22. }
  23.  
  24. }, timeForSetInterver)
  25.  
  26. }
Add Comment
Please, Sign In to add comment