Javascript onmousemove

时间:2018-12-18 17:32:30

标签: javascript onmouseover onmouseout onmousedown 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;
            }
        })

1 个答案:

答案 0 :(得分:0)

一种更简单的方法可能是监听“ onmousemove”事件。您还可能希望将防抖动功能调用将您将要具有的多个顺序调用归为一组。查看Lodash的debounceCheck this article out too.