touch事件学习

    window.onload = function(){
        
        var touch = {
        
            movetarget : false,
            
            touchStart : function (e) {
                console.log('touchestart');                
                t = e.touches[0];
                console.log(t.clientX + ':' + t.clientY);
            },
            
            touchMove : function(e){ //touchstart
                    console.log(e.type);                    
                    this.movetarget = e;                    
                    t = e.touches[0];
                    console.log(t.clientX + ':' + t.clientY);
                    oElement = document.elementFromPoint(t.clientX, t.clientY);
                    console.log(oElement);                    
                    document.getElementById("info").innerHTML = e.type + t.clientX + ':' + t.clientY + ' ' + oElement.innerHTML;
            },
            
            touchEnd : function(e){ //touchstart
                    console.log(e.type);
                    console.log(e);
                    console.log(this.movetarget);                    
                    t = this.movetarget.touches[0];
                    console.log(t.clientX + ':' + t.clientY);                    
                    document.getElementById("info").innerHTML = e.type + t.clientX + ':' + t.clientY ;
            },
            
            init : function(){            
                var content = document.getElementById("content");
                
                content.addEventListener('touchstart', this.touchStart, false);
                content.addEventListener('touchend', this.touchEnd, false);
                content.addEventListener('touchmove', this.touchMove, false);
            }
    
        }
        
        touch.init();
    }
原文地址:https://www.cnblogs.com/mitang/p/4552382.html