R
R
Roman Tyurin2015-11-12 14:39:35
JavaScript
Roman Tyurin, 2015-11-12 14:39:35

How to calculate the scroll step?

What are the solutions to calculate the scroll step (difference between the previous and next value). It doesn't matter how the page scrolls with the mouse wheel or in any other way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-11-12
@Roman-T

var $win = $(window), $doc = $(document), prevPoint = $win.scrollTop();

$doc.scroll(function(){
   var curScroll = $win.scrollTop();
   console.log( curScroll - prevPoint );
   prevPoint = curScroll; 
});

But here's the catch - onscroll works randomly, the resulting gaps can hardly be called steps.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question