Javascript 使用RxJS同时单击鼠标左键和右键
我需要用RxJS同时按下鼠标左键和右键捕捉事件。更准确地说,您需要用鼠标左键和右键捕捉mouseup事件,最大差值为300毫秒Javascript 使用RxJS同时单击鼠标左键和右键,javascript,rxjs,Javascript,Rxjs,我需要用RxJS同时按下鼠标左键和右键捕捉事件。更准确地说,您需要用鼠标左键和右键捕捉mouseup事件,最大差值为300毫秒 创建两个流,一个用于左键单击,另一个用于右键单击 将这两个映射到Date.now() 然后,您需要combinelatetest这两个流 最后,过滤间隔超过300ms的值 根据 从'rxjs'导入{fromEvent,CombineTest} 从“rxjs/operators”导入{filter,map} const upLeft$=fromEvent(文档“mouse
Date.now()
combinelatetest
这两个流过滤
间隔超过300ms的值从'rxjs'导入{fromEvent,CombineTest}
从“rxjs/operators”导入{filter,map}
const upLeft$=fromEvent(文档“mouseup”).pipe(过滤器((e)=>e.which==1),map(()=>Date.now())
const-vertight$=fromEvent(文档“mouseup”).pipe(过滤器((e)=>e.which==3),map(()=>Date.now())
const combined$=combinelatetest(upLeft$,直立$).pipe(过滤器((e)=>(e[1]-e[0])0),map((e)=>(e[1]-e[0]);
合并美元订阅(()=>{
log(“它工作!!!”)
});
您可能需要Math.abs(e[1]-e[0])
import { fromEvent, combineLatest } from 'rxjs'
import { filter, map } from 'rxjs/operators'
const upLeft$ = fromEvent(document, 'mouseup').pipe(filter((e) => e.which === 1), map(()=>Date.now()))
const upRight$ = fromEvent(document, 'mouseup').pipe(filter((e) => e.which === 3), map(()=>Date.now()))
const combined$ = combineLatest(upLeft$ , upRight$).pipe(filter((e)=> (e[1]-e[0])<=300 && (e[1]-e[0])>0), map((e)=> (e[1]-e[0])));
combined$.subscribe(() => {
console.log("It work!!!")
});