js获取鼠标移动坐标


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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM