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


TypeScript pointer.copyCoords方法代碼示例

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


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

示例1: resume

function resume (
  { interaction, event, pointer, eventTarget }: Interact.SignalArg,
  scope: Interact.Scope
) {
  const state = interaction.inertia

  // Check if the down event hits the current inertia target
  if (state.active) {
    let element = eventTarget

    // climb up the DOM tree from the event target
    while (utils.is.element(element)) {
      // if interaction element is the current inertia target element
      if (element === interaction.element) {
        // stop inertia
        raf.cancel(state.timeout)
        state.active = false
        interaction.simulation = null

        // update pointers to the down event's coordinates
        interaction.updatePointer(pointer, event, eventTarget, true)
        utils.pointer.setCoords(
          interaction.coords.cur,
          interaction.pointers.map((p) => p.pointer),
          interaction._now()
        )

        // fire appropriate signals
        const signalArg = {
          interaction,
        }

        scope.interactions.signals.fire('action-resume', signalArg)

        // fire a reume event
        const resumeEvent = new scope.InteractEvent(
          interaction, event, interaction.prepared.name, EventPhase.Resume, interaction.element)

        interaction._fireEvent(resumeEvent)

        utils.pointer.copyCoords(interaction.coords.prev, interaction.coords.cur)
        break
      }

      element = utils.dom.parentNode(element)
    }
  }
}
開發者ID:taye,項目名稱:interact.js,代碼行數:48,代碼來源:index.ts

示例2: inertiaTick

function inertiaTick (interaction: Interact.Interaction) {
  updateInertiaCoords(interaction)
  utils.pointer.setCoordDeltas(interaction.coords.delta, interaction.coords.prev, interaction.coords.cur)
  utils.pointer.setCoordVelocity(interaction.coords.velocity, interaction.coords.delta)

  const state = interaction.inertia
  const options = getOptions(interaction)
  const lambda = options.resistance
  const t = interaction._now() / 1000 - state.t0

  if (t < state.te) {
    const progress =  1 - (Math.exp(-lambda * t) - state.lambda_v0) / state.one_ve_v0

    if (state.modifiedXe === state.xe && state.modifiedYe === state.ye) {
      state.sx = state.xe * progress
      state.sy = state.ye * progress
    }
    else {
      const quadPoint = utils.getQuadraticCurvePoint(
        0, 0,
        state.xe, state.ye,
        state.modifiedXe, state.modifiedYe,
        progress)

      state.sx = quadPoint.x
      state.sy = quadPoint.y
    }

    interaction.move()

    state.timeout = raf.request(() => inertiaTick(interaction))
  }
  else {
    state.sx = state.modifiedXe
    state.sy = state.modifiedYe

    interaction.move()
    interaction.end(state.startEvent)
    state.active = false
    interaction.simulation = null
  }

  utils.pointer.copyCoords(interaction.coords.prev, interaction.coords.cur)
}
開發者ID:taye,項目名稱:interact.js,代碼行數:44,代碼來源:index.ts

示例3: getOptions

function release<T extends Interact.ActionName> (
  { interaction, event, noPreEnd }: Interact.SignalArg,
  scope: Interact.Scope
) {
  const state = interaction.inertia

  if (!interaction.interacting() ||
    (interaction.simulation && interaction.simulation.active) ||
  noPreEnd) {
    return null
  }

  const options = getOptions(interaction)

  const now = interaction._now()
  const { client: velocityClient } = interaction.coords.velocity
  const pointerSpeed = utils.hypot(velocityClient.x, velocityClient.y)

  let smoothEnd = false
  let modifierResult: ReturnType<typeof modifiers.setAll>

  // check if inertia should be started
  const inertiaPossible = (options && options.enabled &&
                     interaction.prepared.name !== 'gesture' &&
                     event !== state.startEvent)

  const inertia = (inertiaPossible &&
    (now - interaction.coords.cur.timeStamp) < 50 &&
    pointerSpeed > options.minSpeed &&
    pointerSpeed > options.endSpeed)

  const modifierArg = {
    interaction,
    pageCoords: utils.extend({}, interaction.coords.cur.page),
    states: inertiaPossible && interaction.modifiers.states.map(
      (modifierStatus) => utils.extend({}, modifierStatus)
    ),
    preEnd: true,
    prevCoords: undefined,
    requireEndOnly: null,
  }

  // smoothEnd
  if (inertiaPossible && !inertia) {
    modifierArg.prevCoords = interaction.prevEvent.page
    modifierArg.requireEndOnly = false
    modifierResult = modifiers.setAll(modifierArg)

    if (modifierResult.changed) {
      smoothEnd = true
    }
  }

  if (!(inertia || smoothEnd)) { return null }

  utils.pointer.copyCoords(state.upCoords, interaction.coords.cur)

  interaction.pointers[0].pointer = state.startEvent = new scope.InteractEvent(
    interaction,
    event,
    // FIXME add proper typing Action.name
    interaction.prepared.name as T,
    EventPhase.InertiaStart,
    interaction.element,
  )

  state.t0 = now

  state.active = true
  state.allowResume = options.allowResume
  interaction.simulation = state

  interaction.interactable.fire(state.startEvent)

  if (inertia) {
    state.vx0 = interaction.coords.velocity.client.x
    state.vy0 = interaction.coords.velocity.client.y
    state.v0 = pointerSpeed

    calcInertia(interaction, state)

    utils.extend(modifierArg.pageCoords, interaction.coords.cur.page)

    modifierArg.pageCoords.x += state.xe
    modifierArg.pageCoords.y += state.ye
    modifierArg.prevCoords = undefined
    modifierArg.requireEndOnly = true

    modifierResult = modifiers.setAll(modifierArg)

    state.modifiedXe += modifierResult.delta.x
    state.modifiedYe += modifierResult.delta.y

    state.timeout = raf.request(() => inertiaTick(interaction))
  }
  else {
    state.smoothEnd = true
    state.xe = modifierResult.delta.x
    state.ye = modifierResult.delta.y

//.........這裏部分代碼省略.........
開發者ID:taye,項目名稱:interact.js,代碼行數:101,代碼來源:index.ts


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