Skip to content

Instantly share code, notes, and snippets.

@MarshalW
Created April 18, 2013 06:33
Show Gist options
  • Save MarshalW/5410626 to your computer and use it in GitHub Desktop.
Save MarshalW/5410626 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
body {
background-color: darkkhaki;
width: 360px;
height: 600px;
}
</style>
<script src="jquery-1.9.1.min.js"></script>
</head>
<body id="content">
<script>
$('body').on('touchstart touchmove touchend', function (event) {
console.log('>>>>>>>touch ' + event.type);
var x = event.originalEvent.touches;
console.log("page x: " + event.originalEvent.a);
});
$(document).ready(function () {
setTimeout(function () {
console.log('>>>>>>generate touch:');
var event = document.createEvent('TouchEvent');
event.initUIEvent('touchstart', true, true);
// event.view = window;
// event.altKey = false;
// event.ctrlKey = false;
// event.shiftKey = false;
// event.metaKey = false;
event.a='111';
event.touches = [
{
pageX: 10
}
];
var element = document.getElementById('content');
element.dispatchEvent(event);
}, 2000);
});
</script>
</body>
</html>
@guotingchao
Copy link

这个模拟是实现不了的吧 如果要针对坐标的话

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment