繁体   English   中英

鼠标滚轮速度

[英]Mouse scroll wheel speed

我正在使用此代码将滚动条绑定到页面上的特定元素。 是否可以更改滚动速度? 我尝试使用“动画”,但是没有用。

    (function() {
  var delay = false;

  $(document).on('mousewheel DOMMouseScroll', function(event) {
    event.preventDefault();
    if(delay) return;

    delay = true;
    setTimeout(function(){delay = false},100)

    var wd = event.originalEvent.wheelDelta || -event.originalEvent.detail;

    var a= document.getElementsByTagName('section');
    if(wd < 0) {
      for(var i = 0 ; i < a.length ; i++) {
        var t = a[i].getClientRects()[0].top;
        if(t >= 40) break;
      }
    }
    else {
      for(var i = a.length-1 ; i >= 0 ; i--) {
        var t = a[i].getClientRects()[0].top;
        if(t < -20) break;
      }
    }
    $('html,body').animate({
      scrollTop: a[i].offsetTop
    });
  });
})();

尝试如下更新Animate方法。

 $('html,body').animate({
  scrollTop: a[i].offsetTop
}, 500);

使用Nicescroll插件

  $(document).ready(function() { $("#divexample1").niceScroll(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://areaaperta.com/nicescroll/js/jquery.nicescroll.min.js"></script> <div class="txtblock"> <h1> Simple scrollable div</h1> <div id="divexample1"> 1 Fermat's conjecture (History)<br /> 2 Mathematical context<br /> 2.1 Pythagorean triples<br /> 2.2 Diophantine equations<br /> 3 Fermat's conjecture<br /> 4 Proofs for specific exponents<br /> 5 Sophie Germain<br /> 6 Ernst Kummer and the theory of ideals<br /> 7 Mordell conjecture<br /> 8 Rational exponents<br /> 9 Computational studies<br /> 10 Connection with elliptic curves<br /> 11 Wiles' general proof<br /> 12 Did Fermat possess a general proof?<br /> 13 Monetary prizes<br /> 14 In popular culture<br /> 15 See also<br /> 16 Notes<br /> 17 References<br /> 18 Bibliography<br /> 19 Further reading<br /> 20 External links </div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM