Skip to content

Instantly share code, notes, and snippets.

@irae
Created March 11, 2014 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irae/9492655 to your computer and use it in GitHub Desktop.
Save irae/9492655 to your computer and use it in GitHub Desktop.
Touch Simulation with steps
function touchSequence(params) {
var step = 0,
config = {
target: params.target || document,
startX: params.startX || 300,
startY: params.startY || 300,
endX: params.endX || 300,
endY: params.endY || 300,
steps: params.steps || 4,
interval: params.interval || 25
},
stepX = (config.endX - config.startX) / config.steps,
touchId = +new Date() + Math.random();
function doTouch() {
var evt = document.createEvent('TouchEvent'),
type = (step === 0) ? 'touchstart' :
(step === config.steps) ? 'touchend' :
'touchmove',
curX = config.startX + stepX * step,
touch = document.createTouch(window, config.target, touchId, curX, config.startY, curX, config.startY),
touchList = document.createTouchList(touch);
if (type === 'touchend') {
touchList = [];
}
evt.initTouchEvent(type, true, true, window, 0,
curX, params.startY, curX, params.startY,
false, false, false, false,
touchList, touchList, touchList,
1, 0);
config.target.dispatchEvent(evt);
if (step !== config.steps) {
step++;
setTimeout(doTouch, config.interval);
}
}
doTouch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment