单双击事件

98 阅读1分钟
function click(){
    this.index = this.index == 0 ? 1 : this.index + 1;  
    this.tt && clearTimeout(this.tt);
    if (this.index == 1) {  
        this.start_time = new Date().getTime(); 
        this.tt =  setTimeout(()=>{  
            console.log('单击');
            this.index = this.start_time = this.end_time = 0;  
            this.tt && clearTimeout(this.tt);
        },200)  
    } else if (this.index == 2) {  
        this.end_time = new Date().getTime();  
        if (this.end_time - this.start_time < 300) {  
            console.log('双击了屏幕');
        }
        this.index = this.start_time = this.end_time = 0;  
    }
}