zoukankan      html  css  js  c++  java
  • js监听网页页面滑动滚动事件,实现导航栏自动显示或隐藏

    /**
    * 页面滑动滚动事件
    * @param e
    */
    //0为隐藏,1为显示
    var s = 1;

    function scrollFunc(e) {
    // e存在就用e不存在就用windon.event
    e = e || window.event;
    // 先判断是什么浏览器
    if (e.wheelDelta) {
    // 浏览器IE,谷歌
    if (e.wheelDelta > 0) {
    //当滑轮向上滚动时
    // console.log("滑轮向上滚动");
    if (s == 0) {
    //向下滑动
    $(".div2").slideDown("slow");
    s = 1;
    }
    }
    if (e.wheelDelta < 0) {
    //当滑轮向下滚动时
    // console.log("滑轮向下滚动");
    if (s == 1) {
    //向上滑动
    $(".div2").slideUp("slow");
    s = 0;
    }
    }
    } else if (e.detail) {
    //浏览器Firefox
    if (e.detail > 0) {
    //当滑轮向上滚动时
    // console.log("滑轮向上滚动");
    if (s == 0) {
    //向下滑动
    $(".div2").slideDown("slow");
    s = 1;
    }
    }
    if (e.detail < 0) {
    //当滑轮向下滚动时
    // console.log("滑轮向下滚动");
    if (s == 1) {
    //向上滑动
    $(".div2").slideUp("slow");
    s = 0;
    }
    }
    }
    }

    //给页面绑定滑轮滚动事件
    if (document.addEventListener) {
    //firefox浏览器
    document.addEventListener('DOMMouseScroll', scrollFunc, false);
    }
    //ie 谷歌浏览器
    window.onmousewheel = document.onmousewheel = scrollFunc;
  • 相关阅读:
    鼠标单击事件( onclick )
    什么是事件《js》
    作业
    javaben的设计规则
    cookie的相关方法
    cookie 基本用法
    include 指令与动作区别
    简单的购物车应用案例 相关代码4
    简单的购物车应用案例 相关代码3
    iOS UI 布局
  • 原文地址:https://www.cnblogs.com/c2g5201314/p/11689477.html
Copyright © 2011-2022 走看看