zoukankan      html  css  js  c++  java
  • [RxJS@7.0.0] AnimationFrames demo

    import {defer, animationFrames, fromEvent} from 'rxjs'
    import { animationFrame } from 'rxjs/internal/scheduler/animationFrame'
    import {endWith, map, tap, takeWhile, finalize, mergeMap, concatMap, switchMap } from 'rxjs/operators'
    const animation = (duration: number, distance: number) => defer(() => {
      const div = document.createElement('div')
      document.body.appendChild(div)
      div.className = 'square'
    
      return animationFrames()
        .pipe(
          map(ms => ms / duration),
          takeWhile(s => s < 1), // take max duaration time
          endWith(1),
          map(v => v * distance),
          tap(x => (div.style.transform = `translate3d(${x}px, 0px, 0px)`)),
          finalize(() => {
            div.remove()
          })
        )
    })
    
    const button = document.querySelector("#animationBtn")
    fromEvent(button, 'click')
      .pipe(
        mergeMap(div => animation(1000, 800)),
        // switchMap(div => animation(1000, 800)),
        // concatMap(div => animation(1000, 800))
      ).subscribe()
    
    animation(2000, 300).subscribe()
    

      

  • 相关阅读:
    [转载]我的WafBypass之道(Misc篇)
    7.3 使用while 循环来处理列表和字典
    7-4__7-7练习
    7.2 while 循环
    第 7 章 用户输入和while 循环
    6.字典练习
    6.4 嵌套
    6.3 遍历字典
    6.2练习
    第 6 章 字典
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12783860.html
Copyright © 2011-2022 走看看