本文整理汇总了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)
})
示例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
}