首页 > 移动平台 > 详细

js获取鼠标移动坐标

时间:2017-03-31 18:15:14      阅读:222      评论:0      收藏:0      [点我收藏+]

js获取鼠标移动坐标,很多情况下还需要考虑document.documentElement.scrollLeft 、 document.documentElement.clientLeft;

    var _touchstart, _touchend,_touchmove;
    var isPC=window.ontouchstart===undefined;
    if(isPC){
        _touchstart="mousedown";
        _touchmove="mousemove";
        _touchend="mouseup";
    }else{
        _touchstart="touchstart";
        _touchmove="touchmove";
        _touchend="touchend";
    }
    var sx,sy,ex,ey;
    document.addEventListener(_touchstart,function(event){
        if(isPC){
            sx=event.clientX;
            sy=event.clientY;
        }else{
            sx=event.targetTouches[0].pageX;
            sy=event.targetTouches[0].pageY;
        }
    },false);
    document.addEventListener(_touchmove,function(){
        if(isPC){
            ex=event.clientX;
            ey=event.clientY;
        }else{
            ex=event.targetTouches[0].pageX;
            ey=event.targetTouches[0].pageY;
        }
    },false);
    document.addEventListener(_touchend,function(){
        if(isPC){
            ex=event.clientX;
            ey=event.clientY;
        }else{
            ex=event.targetTouches[0].pageX;
            ey=event.targetTouches[0].pageY;
        }
    },false);

 

js获取鼠标移动坐标

原文:http://www.cnblogs.com/mrGan/p/6652011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!