Mouse scroll wheel speed

I am using this code to bind scroll to specific elements on page. Is it possible to change the speed of scrolling ? I tried to use "animate" but didn`t work.

    (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
    });
  });
})();

Upvotes: 0

Views: 816

Answers (2)

Rafiqul Islam
Rafiqul Islam

Reputation: 1646

Use Nicescroll Plugin

 $(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>

Upvotes: 0

Banshi Lal Dangi
Banshi Lal Dangi

Reputation: 685

Try to update Animate method as follows.

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

Upvotes: 1

Related Questions