• remove onclick delay on webkit for iphone


    function NoClickDelay(el) {
        this.element = el;
        if( window.Touch ) this.element.addEventListener('touchstart', this, 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();
            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);
            }
        }
    };
  • 相关阅读:
    Struts2完全解耦和
    storm 错误汇总
    sublime3 在ubuntu下不能输入中文
    sublime3 10款必备插件
    sublime3 SublimeREPL python3
    sublime3 Package Control不能使用
    Buffer ByteBuffer 缓冲区
    redis cluster批量插入
    延期执行的方案计策略汇总
    linux 免密登录
  • 原文地址:https://www.cnblogs.com/newBlash/p/4682423.html
Copyright © 2020-2023  润新知