Skip to content

bindEvent里为什么要写 this.onmousemove && this.onmousemove(e); 这一句呢? #69

@JrLou

Description

@JrLou

您好,看了代码以后这一处地方不是很理解:

//绑定事件
bindEvent(){
...
this.onmousemove = window.onmousemove;
window.onmousemove = e => {
this.current.x = e.clientX - this.el.offsetLeft + document.scrollingElement.scrollLeft;
this.current.y = e.clientY - this.el.offsetTop + document.scrollingElement.scrollTop;
this.onmousemove && this.onmousemove(e);
};
...
}

为什么要在这里调用一下 this.onmousemove 方法?
我的疑惑是: 第一次调用bindEvent,这里的 window.onmousemove是 null,那么这一句不会执行;而如果第二次执行(不先destroy的情况下),会造成死循环。望指教 ^_^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions