码迷,mamicode.com
首页 > Web开发 > 详细

jquery 上下滚动显示隐藏

时间:2018-01-18 16:59:48      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:nbsp   body   after   add   als   func   判断   span   ==   

 

 

    function scroll(fn) {
        var beforeScrollTop = document.body.scrollTop,
            fn = fn || function() {};
        window.addEventListener("ontouchmove", function() {
            var afterScrollTop = document.body.scrollTop,
                delta = afterScrollTop - beforeScrollTop;
            if (delta === 0) return false;
            fn(delta > 0 ? "down" : "up");
            beforeScrollTop = afterScrollTop;
        }, false);
    }

 

2,sass转译

@function rem($n) {
        @return $n / 40 + rem;
}

 

3,js判断鼠标上下滚动;

<script type="text/javascript">  
        var scrollFunc = function (e) {  
          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("滑轮向下滚动");  
              }  
          }  
      }  
       //给页面绑定滑轮滚动事件  
      if (document.addEventListener) {//firefox  
          document.addEventListener(‘DOMMouseScroll‘, scrollFunc, false);  
      }  
      //滚动滑轮触发scrollFunc方法  //ie 谷歌  
      window.onmousewheel = document.onmousewheel = scrollFunc;   
    </script> 

 

4,判断鼠标、滚动条上下滚动

            var windowTop = 0;
            $(window).scroll(function() {
                var scrolls = $(this).scrollTop();
                if(scrolls < 5 || scrolls <= windowTop) {
                    // 向上滚动显示
                    console.log(‘向上‘)
                    windowTop = scrolls;
                } else {
                    // 向下滚动隐藏
                    console.log(‘向下‘)
                    windowTop = scrolls;
                }
            });

 

 

 

jquery 上下滚动显示隐藏

标签:nbsp   body   after   add   als   func   判断   span   ==   

原文地址:https://www.cnblogs.com/tanxiang6690/p/8310078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!