當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript popcorn.mix函數代碼示例

本文整理匯總了TypeScript中@popmotion/popcorn.mix函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mix函數的具體用法?TypeScript mix怎麽用?TypeScript mix使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mix函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: scrubber


//.........這裏部分代碼省略.........
      } = props;

      let playhead = scrubber({ from, to, ease }).start(update);

      let currentProgress = 0;
      let process: Process;
      let isActive = false;
      const reverseTween = () => {
        if (elapsed > duration) {
          const remainder = elapsed - duration;
          elapsed = elapsed - remainder * 2;
        } else if (elapsed < 0) {
          const remainder = -1 * elapsed;
          elapsed = elapsed + remainder * 2;
        }
        playDirection *= -1;
      };

      const isTweenComplete = (): boolean => {
        const isComplete =
          playDirection === 1
            ? isActive && elapsed >= duration
            : isActive && elapsed <= 0;

        if (!isComplete) return false;
        if (isComplete && !loop && !flip && !yoyo) return true;

        let isStepTaken = false;
        if (loop && loopCount < loop) {
          elapsed = duration - elapsed;
          loopCount++;
          isStepTaken = true;
        } else if (flip && flipCount < flip) {
          elapsed = duration - elapsed;

          [from, to] = [to, from];
          playhead = scrubber({ from, to, ease }).start(update);

          flipCount++;
          isStepTaken = true;
        } else if (yoyo && yoyoCount < yoyo) {
          reverseTween();
          yoyoCount++;
          isStepTaken = true;
        }

        return !isStepTaken;
      };

      const updateTween = () => {
        currentProgress = clampProgress(progress(0, duration, elapsed));
        playhead.seek(currentProgress);
      };

      const startTimer = () => {
        isActive = true;
        process = sync.update(({ delta }) => {
          // TODO Maybe try something different to eat the variations in framerate
          elapsed += delta * playDirection;
          updateTween();
          if (isTweenComplete() && complete) {
            cancelSync.update(process);
            sync.update(complete, false, true);
          }
        }, true);
      };

      const stopTimer = () => {
        isActive = false;
        if (process) cancelSync.update(process);
      };

      startTimer();

      return {
        isActive: () => isActive,
        getElapsed: () => clamp(0, duration, elapsed),
        getProgress: () => currentProgress,
        stop() {
          stopTimer();
        },
        pause() {
          stopTimer();
          return this;
        },
        resume() {
          if (!isActive) startTimer();
          return this;
        },
        seek(newProgress: number) {
          elapsed = mix(0, duration, newProgress);
          sync.update(updateTween, false, true);
          return this;
        },
        reverse() {
          reverseTween();
          return this;
        }
      };
    }
開發者ID:Popmotion,項目名稱:popmotion,代碼行數:101,代碼來源:index.ts

示例2: progress

export const steps = (st: number, min = 0, max = 1) => (v: number) => {
  const current = progress(min, max, v);
  return mix(min, max, stepProgress(st, current));
};
開發者ID:Popmotion,項目名稱:popmotion,代碼行數:4,代碼來源:transformers.ts

示例3:

 update: ([va, vb]: [number, number]) => {
   observer.update(mix(va, vb, balance));
 }
開發者ID:Popmotion,項目名稱:popmotion,代碼行數:3,代碼來源:crossfade.ts

示例4: mix

 (v: number) => mix(from, to, v)
開發者ID:Popmotion,項目名稱:popmotion,代碼行數:1,代碼來源:scrubber.ts


注:本文中的@popmotion/popcorn.mix函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。