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

<!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>

 

posted @ 2015-05-17 21:39  范小武  阅读(605)  评论(0编辑  收藏  举报