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


TypeScript clamp.default函數代碼示例

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


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

示例1: scrollTo

export function scrollTo(
  scrollbar: I.Scrollbar,
  x: number,
  y: number,
  duration = 0,
  { easing = defaultEasing, callback = null }: Partial<I.ScrollToOptions> = {},
) {
  const {
    options,
    offset,
    limit,
  } = scrollbar;

  if (options.renderByPixels) {
    // ensure resolved with integer
    x = Math.round(x);
    y = Math.round(y);
  }

  const startX = offset.x;
  const startY = offset.y;

  const disX = clamp(x, 0, limit.x) - startX;
  const disY = clamp(y, 0, limit.y) - startY;

  const start = Date.now();

  function scroll() {
    const elapse = Date.now() - start;
    const progress = duration ? easing(Math.min(elapse / duration, 1)) : 1;

    scrollbar.setPosition(
      startX + disX * progress,
      startY + disY * progress,
    );

    if (elapse >= duration) {
      if (typeof callback === 'function') {
        callback.call(scrollbar);
      }
    } else {
      const animationID = requestAnimationFrame(scroll);
      animationIDStorage.set(scrollbar, animationID);
    }
  }

  cancelAnimationFrame(animationIDStorage.get(scrollbar) as number);
  scroll();
}
開發者ID:regangully,項目名稱:regangully.github.io,代碼行數:49,代碼來源:scroll-to.ts

示例2: addEvent

  addEvent(container, 'click', (evt: MouseEvent) => {
    if (isMouseMoving || !isOneOf(evt.target, [xAxis.element, yAxis.element])) {
      return;
    }

    const track = evt.target as HTMLElement;
    const direction = getTrackDirection(track);
    const rect = track.getBoundingClientRect();
    const clickPos = getPosition(evt);

    const { offset, limit } = scrollbar;

    if (direction === Direction.X) {
      const offsetOnTrack = clickPos.x - rect.left - xAxis.thumb.displaySize / 2;
      scrollbar.setMomentum(
        clamp(calcOffset(direction, offsetOnTrack) - offset.x, -offset.x, limit.x - offset.x),
        0,
      );
    }

    if (direction === Direction.Y) {
      const offsetOnTrack = clickPos.y - rect.top - yAxis.thumb.displaySize / 2;
      scrollbar.setMomentum(
        0,
        clamp(calcOffset(direction, offsetOnTrack) - offset.y, -offset.y, limit.y - offset.y),
      );
    }
  });
開發者ID:regangully,項目名稱:regangully.github.io,代碼行數:28,代碼來源:mouse.ts

示例3: scroll

  function scroll({ x, y }) {
    if (!x && !y) return;

    // DISALLOW delta transformation
    scrollbar.setMomentum(
      clamp(offset.x + x, 0, limit.x) - offset.x,
      clamp(offset.y + y, 0, limit.y) - offset.y,
    );

    animationID = requestAnimationFrame(() => {
      scroll({ x, y });
    });
  }
開發者ID:vhuy2571990,項目名稱:vhuy2571990.github.io,代碼行數:13,代碼來源:select.ts

示例4: scrollIntoView

export function scrollIntoView(
  scrollbar: I.Scrollbar,
  elem: HTMLElement,
  {
    alignToTop = true,
    onlyScrollIfNeeded = false,
    offsetTop = 0,
    offsetLeft = 0,
    offsetBottom = 0,
  }: Partial<I.ScrollIntoViewOptions> = {},
) {
  const {
    containerEl,
    bounding,
    offset,
    limit,
  } = scrollbar;

  if (!elem || !containerEl.contains(elem)) return;

  const targetBounding = elem.getBoundingClientRect();

  if (onlyScrollIfNeeded && scrollbar.isVisible(elem)) return;

  const delta = alignToTop ? targetBounding.top - bounding.top - offsetTop : targetBounding.bottom - bounding.bottom + offsetBottom;

  scrollbar.setMomentum(
    targetBounding.left - bounding.left - offsetLeft,
    clamp(delta, -offset.y, limit.y - offset.y),
  );
}
開發者ID:regangully,項目名稱:regangully.github.io,代碼行數:31,代碼來源:scroll-into-view.ts

示例5: setPosition

export function setPosition(
  scrollbar: I.Scrollbar,
  x: number,
  y: number,
): I.ScrollStatus | null {
  const {
    options,
    offset,
    limit,
    track,
    contentEl,
  } = scrollbar;

  if (options.renderByPixels) {
    x = Math.round(x);
    y = Math.round(y);
  }

  x = clamp(x, 0, limit.x);
  y = clamp(y, 0, limit.y);

  // position changed -> show track for 300ms
  if (x !== offset.x) track.xAxis.show();
  if (y !== offset.y) track.yAxis.show();

  if (!options.alwaysShowTracks) {
    track.autoHideOnIdle();
  }

  if (x === offset.x && y === offset.y) {
    return null;
  }

  offset.x = x;
  offset.y = y;

  setStyle(contentEl, {
    '-transform': `translate3d(${-x}px, ${-y}px, 0)`,
  });

  track.update();

  return {
    offset: { ...offset },
    limit: { ...limit },
  };
}
開發者ID:regangully,項目名稱:regangully.github.io,代碼行數:47,代碼來源:set-position.ts

示例6: return

  return (proto: any, key: string) => {
    const alias = `_${key}`;

    Object.defineProperty(proto, key, {
      get() {
        return this[alias];
      },
      set(val: number) {
        Object.defineProperty(this, alias, {
          value: clamp(val, min, max),
          enumerable: false,
          writable: true,
          configurable: true,
        });
      },
      enumerable: true,
      configurable: true,
    });
  };
開發者ID:regangully,項目名稱:regangully.github.io,代碼行數:19,代碼來源:range.ts


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