Last active
September 22, 2015 07:27
-
-
Save perchouli/44407b632c996dbf4a81 to your computer and use it in GitHub Desktop.
Trigger touch event (Firefox)
This file contains 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
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