您的位置:首页 > 移动开发

深入理解移动端touch事件

2016-05-23 17:57 363 查看

相关链接:http://blog.csdn.net/cometwo/article/details/50534611



<!DOCTYPE html>
<html lang="en">

<head>

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta charset="UTF-8" />
<title>Document</title>

<style type="text/css">
div {
width: 200px;
height: 200px;
background: red;
margin: 0 auto;
}
</style>
<script type="text/javascript">
window.onload = function() {
document.getElementById('touch').ontouchmove = function(e) {
console.log(e.type);
};
document.getElementById('touch').ontouchend = function(e) {
console.log(e.type);
};
document.getElementById('touch').onclick = function(e) {
console.log(e.type);
};
document.getElementById('touch').ontouchstart = function(e) {
console.log(e.type + ';' + e.target.nodeName );
};

}
</script>
</head>

<body>
<div id="touch"></div>

</body>

</html>


JQuery 强迫症患者

<!DOCTYPE html>
<html lang="en">

<head>

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta charset="UTF-8" />
<script type="text/javascript" src="jquery-2.1.4.min.js" ></script>
<title>Document</title>

<style type="text/css">
div {
width: 200px;
height: 200px;
background: red;
margin: 0 auto;
}
</style>
<script type="text/javascript">
$( function() {
$("#touch").get(0).ontouchmove = function(e) {
console.log(e.type);
};
$("#touch").get(0).ontouchend = function(e) {
console.log(e.type);
};
$("#touch").get(0).onclick = function(e) {
console.log(e.type);
};
$("#touch").get(0).ontouchstart = function(e) {
console.log(e.type + ';' + e.target.nodeName );
};

})
</script>
</head>

<body>
<div id="touch"></div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: