删除的onclick延迟的webapps为Android [英] removing the onclick delay for webapps for android

查看:160
本文介绍了删除的onclick延迟的webapps为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是建设一个Web应用程序。要删除的onclick延迟,我发现这个脚本上
http://cubiq.org/remove-onclick-delay-on-webkit -for-iphone
在code是bascically -

Hi i'm building a webapp. To remove the onclick delay i found this script on http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone The code is bascically-

function NoClickDelay(el) {
this.element = el;
if( 'ontouchstart' in window ){  
    console.log("===================touch supported :P")
    this.element.addEventListener('touchstart', this.handleEvent, false);
}                              
}

NoClickDelay.prototype = {
handleEvent: function(e) {
     switch(e.type) {
        case 'touchstart': this.onTouchStart(e); break;
        case 'touchmove': this.onTouchMove(e); break;
        case 'touchend': this.onTouchEnd(e); break;
    }
},

onTouchStart: function(e) {

    //e.preventDefault(); //removed to let the page scroll
    this.moved = false;

    this.element.addEventListener('touchmove', this, false);
    this.element.addEventListener('touchend', this, false);
},

onTouchMove: function(e) {

    this.moved = true;
},

onTouchEnd: function(e) {
    this.element.removeEventListener('touchmove', this, false);
    this.element.removeEventListener('touchend', this, false);

    if( !this.moved ) {
        // Place your code here or use the click simulation below
        var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
        if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;

        var theEvent = document.createEvent('MouseEvents');
        theEvent.initEvent('click', true, true);
        theTarget.dispatchEvent(theEvent);
    }
}
};

我的问题是,这适用于iPhone / iPad上而不是在Android上。什么$ P $在Android平台pvents它,我能做些什么,以实现Android和其他设备类似的行为?请帮助。

推荐答案

在你的链接也有人评论有关Android解决方案(我还没有尝试):

In your link there is someone commented about Android solution (I haven't try it):

Android有与laggy onClicks同样的问题。您的演示不能在Android上工作,除非我在下面注释掉window.Touch,所以我相信,DOM属性只在iOS可见。

Android has same problem with laggy onClicks. Your demo doesn’t work on Android, unless I comment out window.Touch below, so I believe that DOM property is only visible on iOS.

function NoClickDelay(el) {
this.element = el;
// if (window.Touch) not available on android
this.element.addEventListener(‘touchstart’, this, false);
}

通过上述变化的Andr​​oid获得非laggy触摸事件!

With the above change Android gets non-laggy touch event!

这篇关于删除的onclick延迟的webapps为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆