码迷,mamicode.com
首页 > 移动开发 > 详细

wap手机端按下 松开 滑动事件

时间:2015-05-17 23:09:08      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"        name="viewport" /> 
    <script type="text/javascript">
        function a() {
            var mdiv = document.getElementById("mdiv");
            var mdiv2 = document.getElementById("mdiv2");
            var mdiv3 = document.getElementById("mdiv3");
            var m = Math, 
            isTouchPad = (/hp-tablet/gi).test(navigator.appVersion), 
            hasTouch = ontouchstart in window && !isTouchPad,
            START_EV = hasTouch ? touchstart : mousedown,
         MOVE_EV = hasTouch ? touchmove : mousemove,
         END_EV = hasTouch ? touchend : mouseup,
         CANCEL_EV = hasTouch ? touchcancel : mouseup;
            mdiv.addEventListener(MOVE_EV, function (e) {
                var point = hasTouch ? e.touches[0] : e;
                mdiv3.innerHTML = "X:" + point.pageX + ";Y:" + point.pageY + "";
            }, false);
            mdiv.addEventListener(START_EV, function (e) {
                var point = hasTouch ? e.touches[0] : e;
                mdiv2.innerHTML = "BeginX:" + point.pageX + ";BeginY:" + point.pageY + "<br/>";
            }, false);
            mdiv.addEventListener(END_EV, function (e) {
                var point = hasTouch ? e.changedTouches[0] : e;
                mdiv2.innerHTML +=( "EndX:" + point.pageX + ";EndY:" + point.pageY + "");
            }, false);
        }
    </script>
</head>
<body onload="a()">
<div style="border: solid 1px #000000; background: #ffffff; width: 100%; height: 299px; margin:auto" id="mdiv"> 
    <div id="mdiv3"> </div>
    <div id="mdiv2"></div>
</div>
</body>
</html>

 

wap手机端按下 松开 滑动事件

标签:

原文地址:http://www.cnblogs.com/fanxiaowu/p/4510549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!