wowchemy-animation.js 648 B

12345678910111213141516171819202122
  1. /*************************************************
  2. * Wowchemy
  3. * https://github.com/wowchemy/wowchemy-hugo-themes
  4. *
  5. * Wowchemy Animation
  6. **************************************************/
  7. function fadeIn(element, duration = 600) {
  8. element.style.display = '';
  9. element.style.opacity = '0';
  10. let last = +new Date();
  11. let tick = function () {
  12. element.style.opacity = (+element.style.opacity + (new Date() - last) / duration).toString();
  13. last = +new Date();
  14. if (+element.style.opacity < 1) {
  15. (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16);
  16. }
  17. };
  18. tick();
  19. }
  20. export {fadeIn};