aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/reading/component/widget/AnimateMethod.scala
blob: dfe3e462702fdc903d3d2b985cdebda07391f0ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package reading.component.widget

object AnimateMethod {
  def fadeOut(id: String, onEnd: => Unit = ()): Unit =
    Animate(
      id = id,
      duration = 100,
      transition = Transition.linear,
      animate =
      (progress, element) => {
        element.style.opacity = s"${1 - progress}"
        element.style.transform = s"translateX(${20 * progress}px)"
      },
      onEnd = onEnd
    )

  def fadeIn(id: String, onEnd: => Unit = ()): Unit =
    Animate(
      id = id,
      duration = 100,
      transition = Transition.easeIn,
      animate =
      (progress, element) => {
        element.style.opacity = s"${progress}"
        element.style.transform = s"translateX(${20 * (1 - progress)}px)"
      },
      onEnd = onEnd
    )
}