I am trying to make number counter which will work on scroll. When you scroll down, then counter is going from 0 to some number, and when you scroll up, from some number to zero. Numbers are changing during the scroll (if there is no scroll, number stay where it is in that time). Any ideas? Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 796 times
        
    2 Answers
1
            
            
        Try this and check your console
HTML
<div class="body">
</div>
jquery
$(window).scroll(function(){
    console.log($(window).scrollTop());
});
css
.body{
    height:900px;
}
 
    
    
        Ankit Singh
        
- 1,477
- 1
- 13
- 22
0
            
            
        Using this answer to determin if the scroll goes up or down:
var lastScrollTop = 0;
var counter = 0;
$(window).scroll(function(event){
   var st = $(this).scrollTop();
   if (st > lastScrollTop){
     counter++;
   } else {
     counter--;
   }
   lastScrollTop = st;
});
 
    
    
        Sveta
        
- 1,041
- 13
- 22
