码迷,mamicode.com
首页 > 其他好文 > 详细

touch事件学习

时间:2015-06-04 19:11:34      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

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

 

touch事件学习

标签:

原文地址:http://www.cnblogs.com/mitang/p/4552382.html

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