花落春仍在、芳草不曾遮

88 阅读1分钟

three之右键双击事件

一。dbmousedown.ts文件

export default function dbmousedown(v:any = '默认',) {
    /* 墨右键双击 */
    let t = 0, total = 0;
    window.addEventListener('mousedown', event => {
        if (event.button != 2) return;
        total += 1;
        if (total === 1) {
            t = new Date().valueOf();
        }
        if (total === 2) {
            let now = new Date().valueOf();
            console.log(now - t);
            if (now - t < 500) {
            
                /* 事件处理函数 */
  
                total = 0;
                t = 0;
            } else {
                total = 1;
                t = now;
            }
        }
    });
}

新右键双击plus版

let timeout:any;

document.addEventListener('contextmenu', function (event) {
    // 阻止默认的右键菜单显示
    event.preventDefault();

    if (!timeoutBol) {
        timeoutBol = true
        // 设置一个定时器,如果在指定时间内再次触发右键,则认为是双击
        timeout = setTimeout(function () {
            timeoutBol = false;
        }, 400); // 这里的300毫秒可以根据需要调整为适当的双击检测时间

    } else {

        // 第二次右键点击发生在300毫秒内,认为是双击
        clearTimeout(timeout);
        timeoutBol = false; // 重置状态
        console.log('鼠标右键双击触发了');
        // 在这里执行你的操作
        handleDoubleClick(event);
    }
    const handleDoubleClick = (event)=>{
    };
}