鼠标左击双击事件dblclick,那右击双击事件呢?
在开发中遇到一个需求,左键双击下钻,右键双击上钻。
貌似没有右键双击事件,自己手写一个
let t = 0,
total = 0;
document.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 < 300){
console.log('右侧双击');
total = 0;
t = 0;
} else {
total = 1;
t = now;
}
}
});