我尝试使用Observable来监视元素的clientX。 像这样:
`const wrap = document.getElementById('wrap');
const body = document.body;
const mouseDown = Observable.fromEvent(wrap, 'mousedown');
const mouseUp = Observable.fromEvent(body, 'mouseup');
const mouseMove = Observable.fromEvent(body, 'mousemove');
mouseDown
.map(event => mouseMove.takeUntil(mouseUp))
.concatAll()
.map(m => ({ x: m.event.clientX , y:m.clientY }))
.subscribe(pos => {
wrap.style.left = pos.x + 'px';
wrap.style.top = pos.y + 'px';
})`
但我在.map(m => ({ x: m.event.clientX , y:m.clientY }))
所述Property 'event' does not exist on type '{}'
我该如何解决?
答案 0 :(得分:0)
您需要更改以下行
.map(m => ({ x: m.event.clientX , y:m.clientY }))
到这个
.map(m => ({ x: m.clientX , y:m.clientY }))
这只是一个简单的错字。