/***
 * Effects Module
 * @module effects
 */

/**
 * Fade in or out the element.
 * @private
 *
 * @param {Element} element A DOM node
 * @param {number} [duration=400] A number determining how long the animation will run
 * @param {boolean} isFadeIn Determine fadeIn or fadeOut
 */
function fade (element, duration = 400, isFadeIn) {
  const opacity = isFadeIn ? 0 : 1
  element.style.opacity = opacity

  let last = +new Date()
  function tick () {
    element.style.opacity = +element.style.opacity + (new Date() - last) / duration
    last = +new Date()

    const targetOpacity = isFadeIn ? +element.style.opacity < 1 : +element.style.opacity > 0
    if (targetOpacity) {
      (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16)
    }
  }

  tick()
}

/**
 * Display the elements by fading them to opaque.
 *
 * @param {Element} element A DOM node
 * @param {number} [duration=400] A number determining how long the animation will run
 */
export function fadeIn (element, duration = 400) {
  fade(element, duration, true)
}

/**
 * Hide the element by fading them to transparent.
 *
 * @param {Element} element A DOM node
 * @param {number} [duration=400] A number determining how long the animation will run
 */
export function fadeOut (element, duration = 400) {
  fade(element, duration, false)
}

/**
 * Hide the element.
 *
 * @param {Element} element A DOM node
 */
export function hide (element) {
  element.style.display = 'none'
}

/**
 * Show the element.
 *
 * @param {Element} element A DOM node
 */
export function show (element) {
  element.style.display = ''
}

@@ -441,24 +441,93 @@
 n tick () %7B%0A
+    const timeDifference = (new Date() - last) * (isFadeIn ? 1 : -1)%0A
     element.
@@ -567,35 +567,30 @@
 acity + 
-(new Date() - last)
+timeDifference
  / durat
@@ -827,16 +827,76 @@
 ck, 16)%0A
+    %7D else %7B%0A      element.style.opacity = isFadeIn ? 1 : 0%0A
     %7D%0A  
@@ -1130,38 +1130,32 @@
 lement, duration
- = 400
 ) %7B%0A  fade(eleme
@@ -1357,32 +1357,32 @@
 on will run%0A */%0A
+
 export function 
@@ -1407,22 +1407,16 @@
 duration
- = 400
 ) %7B%0A  fa

Fix opacity for fadeOut