Created
April 2, 2025 20:14
-
-
Save sketchpunk/2c52e4e158640dc5cb2689335b839df8 to your computer and use it in GitHub Desktop.
Clone and Dispatch Events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clone an event then dispatch it to an HTML Element | |
function dispatchClonedEvent( e: Event, elm:HTMLElement ){ | |
if( e.type.startsWith( 'pointer' ) ){ | |
const evt = e as PointerEvent; | |
elm.dispatchEvent( new PointerEvent( evt.type, { | |
bubbles : evt.bubbles, | |
cancelable : evt.cancelable, | |
clientX : evt.clientX, | |
clientY : evt.clientY, | |
button : evt.button, | |
ctrlKey : evt.ctrlKey, | |
shiftKey : evt.shiftKey, | |
altKey : evt.altKey, | |
metaKey : evt.metaKey | |
})); | |
}else{ | |
console.error( 'Can not dispatch cloned event, event type unknown' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment