Javascript onmousemove

Javascript onmousemove

我想在鼠标移动时显示导航栏,在其他情况下显示导航栏。
怎么办? PS: 没有 jquery 最常用。

代码:向下滚动导航栏隐藏,向上滚动导航栏可见

window.addEventListener('scroll', function () {
            if (position < this.window.pageYOffset) {
                nav.style.visibility = "hidden";
                var navTest = 0;
                position = this.window.pageYOffset;
            }
            //if the mouse is moved then show navbar
            else if(onmousemove){
                nav.style.visibility = "visible";
                position = this.window.pageYOffset;
            }
            else {
                nav.style.visibility = "visible";
                position = this.window.pageYOffset;
            }
        })

更简单的方法可能是监听 'onmousemove' 事件。您还可能希望去抖动函数调用将您将要进行的许多顺序调用组合为一个。查看 Lodash 的 debounce. Check this article out too.