我是靠谱客的博主 欣慰春天,这篇文章主要介绍js判断鼠标滑轮滚动方向并根据滚动…,现在分享给大家,希望可以做个参考。

<script>
    var scrollFunc = function (e) {
        var direct = 0;
        e = e || window.event;
        if (e.wheelDelta) {   //判断浏览器IE,谷歌滑轮事件              
            if (e.wheelDelta > 0) { //当滑轮向上滚动时
                alert(" 滑轮向上滚动");
            }
            if (e.wheelDelta < 0) { //当滑轮向下滚动时
                alert(" 滑轮向下滚动");
            }
        } else if (e.detail) {   //Firefox滑轮事件
            if (e. detail> 0) { //当滑轮向上滚动时
                alert(" 滑轮向上滚动");
            }
            if (e. detail< 0) { //当滑轮向下滚动时
                alert(" 滑轮向下滚动");
            }
        }
        ScrollText(direct);
    }
    //给页面绑定滑轮滚动事件
    if (document.addEventListener) {
        document.addEventListener('DOMMouseScroll', scrollFunc, false);
    }
    //滚动滑轮触发scrollFunc方法
    window.onmousewheel = document.onmousewheel = scrollFunc;  
</script>

最后

以上就是欣慰春天最近收集整理的关于js判断鼠标滑轮滚动方向并根据滚动…的全部内容,更多相关js判断鼠标滑轮滚动方向并根据滚动…内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部