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


TypeScript dom.getPath方法代碼示例

本文整理匯總了TypeScript中@interactjs/utils.dom.getPath方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript dom.getPath方法的具體用法?TypeScript dom.getPath怎麽用?TypeScript dom.getPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@interactjs/utils.dom的用法示例。


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

示例1: setTimeout

  interactions.signals.on('down', ({ interaction, pointer, event, eventTarget, pointerIndex }) => {
    const timer = interaction.pointers[pointerIndex].hold
    const path = utils.dom.getPath(eventTarget)
    const signalArg = {
      interaction,
      pointer,
      event,
      eventTarget,
      type: 'hold',
      targets: [] as EventTargetList,
      path,
      element: null,
    }

    for (const element of path) {
      signalArg.element = element

      signals.fire('collect-targets', signalArg)
    }

    if (!signalArg.targets.length) { return }

    let minDuration = Infinity

    for (const target of signalArg.targets) {
      const holdDuration = target.eventable.options.holdDuration

      if (holdDuration < minDuration) {
        minDuration = holdDuration
      }
    }

    timer.duration = minDuration
    timer.timeout = setTimeout(() => {
      fire({
        interaction,
        eventTarget,
        pointer,
        event,
        type: 'hold',
      }, scope)
    }, minDuration)
  })
開發者ID:taye,項目名稱:interact.js,代碼行數:43,代碼來源:base.ts

示例2:

function collectEventTargets<T extends string> ({ interaction, pointer, event, eventTarget, type }: {
  interaction: Interaction,
  pointer: Interact.PointerType,
  event: Interact.PointerEventType,
  eventTarget: Interact.EventTarget,
  type: T
}) {
  const pointerIndex = interaction.getPointerIndex(pointer)
  const pointerInfo = interaction.pointers[pointerIndex]

  // do not fire a tap event if the pointer was moved before being lifted
  if (type === 'tap' && (interaction.pointerWasMoved ||
      // or if the pointerup target is different to the pointerdown target
      !(pointerInfo && pointerInfo.downTarget === eventTarget))) {
    return []
  }

  const path = utils.dom.getPath(eventTarget)
  const signalArg = {
    interaction,
    pointer,
    event,
    eventTarget,
    type,
    path,
    targets: [] as EventTargetList,
    element: null,
  }

  for (const element of path) {
    signalArg.element = element

    signals.fire('collect-targets', signalArg)
  }

  if (type === 'hold') {
    signalArg.targets = signalArg.targets.filter((target) =>
      target.eventable.options.holdDuration === interaction.pointers[pointerIndex].hold.duration)
  }

  return signalArg.targets
}
開發者ID:taye,項目名稱:interact.js,代碼行數:42,代碼來源:base.ts


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