Extjs 3 ipad drag drop

本文介绍了一种在触摸屏设备上使用 JavaScript 模拟鼠标点击、拖动等操作的方法。通过监听 touchstart、touchmove 和 touchend 事件,并转换为对应的鼠标事件 mousedown、mousemove 和 mouseup。

window.document.body.addEventListener("touchstart", Application.Main.touchStart, false);
window.document.body.addEventListener("touchmove", Application.Main.touchMove, false);
window.document.body.addEventListener("touchend", Application.Main.touchEnd, false);

 

touchStart: function(event) {

Application.Main.dragDropMouseDown = isDefined(Application.Main.dragDropMouseDown)?Application.Main.dragDropMouseDown:false;
Application.Main.dragDropMouseDown = Application.Main.activeMouseDown(event);

if(Application.Main.dragDropMouseDown){
            if (event.touches.length==1){
                var touch = event.touches[0];
                if (!touch) { event.preventDefault(); return (false); }
                var mousedownE = document.createEvent("MouseEvents");
                mousedownE.initMouseEvent('mousedown',true,true,window,
                    1,
                    touch.screenX,
                    touch.screenY,
                    touch.clientX,
                    touch.clientY,
                    false,false,false,false,
                    0,
                    null
                );
                touch.target.dispatchEvent(mousedownE);
                //event.preventDefault();
                //Application.Main.counting(event);
            }
        }
    } catch (exc) { }
},

touchMove: function(event) {
    try {
        if(Application.Main.dragDropMouseDown){
            if (event.touches.length==1){
                var touch = event.touches[0];
                if (!touch) { event.preventDefault(); return (false); }
                var mousemoveE = document.createEvent("MouseEvents");
                mousemoveE.initMouseEvent('mousemove',true,true,window,
                    1,
                    touch.screenX,
                    touch.screenY,
                    touch.clientX,
                    touch.clientY,
                    false,false,false,false,
                    0,
                    null
                );
                touch.target.dispatchEvent(mousemoveE);
            }
            //Application.Main.counting(event);
            event.preventDefault();
        }

        window.clearInterval(Application.Main.d);
    } catch (exc) { }
},
touchEnd: function(event) {
    try {
        if(Application.Main.dragDropMouseDown && event.touches.length==0){
            var touch = event.changedTouches[0];
            if (!touch) { event.preventDefault(); return (false); }
            var mouseupE = document.createEvent("MouseEvents");
            mouseupE.initMouseEvent('mouseup',true,true,window,
                1,
                touch.screenX,
                touch.screenY,
                touch.clientX,
                touch.clientY,
                false,false,false,false,
                0,
                null
            );
            touch.target.dispatchEvent(mouseupE);
            Application.Main.dragDropMouseDown = false;
        }

        window.clearInterval(Application.Main.d);
    } catch (exc) { }
},

activeMouseDown: function(event) {
    if(Application.Main.dragDropMouseDown){
        return true;
    }else{
        var result = false;
        if(event.touches.length==1){
            var targetTouches = event.targetTouches;
            var target = targetTouches[0].target;
            var className = target.className;
            var patten = new RegExp("(x-panel-header|x-window-header|drag)");
            result = patten.test(className);
        }
        return result;
    }
}

 

 

 

 

 

转载于:https://www.cnblogs.com/yubuaishui/archive/2012/03/27/2419759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值