我在setInterval中获取当前鼠标位置。如何使用Typescript和Angular 2完成相同的操作?
我的意思是我可以使用Observables创建一个计时器,但是如何读取该计时器中的当前鼠标位置?
let startX = event.pageX;
setInterval(function(){
let diff = window.mouseX - startX;
console.log(diff);
}, 50)
答案 0 :(得分:0)
你可以这样做:
let startX = event.pageX;
let observable = Observable.create( (observer: any) => {
setInterval(function(){
let diff = window.mouseX - startX;
observer.next(diff);
}, 50)
});