zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    };
  • 相关阅读:
    关于在UNIcode环境下得TCHAR转string类型以及string转TCHAR
    c++重要知识点
    c语言五子棋
    修改单词首字母大小写
    MFC界面分割以及挂载
    c语言操作文件函数大全
    字符串的分割
    简单售货机代码
    Oracle数据库的查询
    oracle数据库四大语言
  • 原文地址:https://www.cnblogs.com/newBlash/p/4682423.html
Copyright © 2011-2022 走看看