Skip to content

Instantly share code, notes, and snippets.

@perchouli
Last active September 22, 2015 07:27
Show Gist options
  • Save perchouli/44407b632c996dbf4a81 to your computer and use it in GitHub Desktop.
Save perchouli/44407b632c996dbf4a81 to your computer and use it in GitHub Desktop.
Trigger touch event (Firefox)
function tiggerTouchEvent(target, type, identifier, x, y) {
//Firefox
var e = document.createEvent('TouchEvent'),
touch = document.createTouch(window, target, identifier),
touches,
targetTouches,
changedTouches;
if (type == 'touchend') {
touches = document.createTouchList();
targetTouches = document.createTouchList();
changedTouches = document.createTouchList(touch);
}
else {
touches = document.createTouchList(touch);
targetTouches = document.createTouchList(touch);
changedTouches = document.createTouchList(touch);
}
e.initTouchEvent(type, true, true, window, 1, false, false, false, false, touches, targetTouches, changedTouches);
// safari / chrome
var e = document.createEvent('UIEvent');
e.initEvent('touchstart', true, true);
target.dispatchEvent(e);
};
tiggerTouchEvent(document.getElementById('touchedDOM'), 'touchstart', Math.random().toString(), 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment