Smooth scrolling on scroll up/down

Smooth scrolling on scroll up/down

I need to animate a scroll from the current screen position up or down, when the scrollbar move up or down.

I'm using this script, but doesn't work ok:

 
  1. var iScrollPos = 0;
  2. $(window).scroll(function () {
  3. var iCurScrollPos = $(this).scrollTop();
  4. if (iCurScrollPos > iScrollPos) {
  5. $('html,body').animate({
  6. scrollTop: $(window).scrollTop() + 100
  7. })
  8. } else {
  9. $('html,body').animate({
  10. scrollTop: $(window).scrollTop() - 100
  11. })
  12. }
  13. iScrollPos = iCurScrollPos;
  14. });

The problem is that a loop appear on the scroll down.