Scrolling can be detected by binding scroll event to window. To determine the scroll direction we need to compare the present scroll position with previous scroll position.

Program Flow

  1. Compare window.pageYOffset with lastScrollPosition - If it is greater the scroll direction is down or the scroll direction is up
  2. Store present window.pageYOffset to lastScrollPosition 

Script

$scope.lastScrollTop = 0;
$scope.direction = "";
angular.element($window).bind("scroll", function() {
      $scope.st = window.pageYOffset;
      if ($scope.st > $scope.lastScrollTop) {
          $scope.direction = "down";
      } else {
          $scope.direction = "up";
      }

      $scope.lastScrollTop = $scope.st;
      $scope.$apply();
      console.log($scope.direction);
 });

5 comments:

  1. How to determine the direction of scroll using angularJS. Scrolling can be detected on window events, Leaving things for essay writing not looking good you have a chance to make best dissertation help things perfect. Ever trying to determine the directions for events.

    ReplyDelete
  2. Hey! We are professional writing team, which are always ready to face with even the most complicated task. So once time we received a rather strange task from our client, who asked us to wrire for him article based on the idea you presented here on your blog "How to Determine the Direction of Scroll using AngularJS" and he emphasized the idea of conducting that paper in the so called form of review on it, so our professional writer agreed to do that difficult task. The result of his efforst you can find at cheap-papers writing platform where you can also order different paper, buy interesting presentations topics and receive professional writing assistance.

    ReplyDelete
  3. I agree with you. I often use additional services. I recently found rewriting services It helps me save my time. I'm very happy to tell you about it.

    ReplyDelete
  4. Good day fellas! Thanks you so much for this script, I will try it as soon as possible! Are you searching for an inexpensive but reliable top online writing company? Then you must go to this brilliant online pro https://payforessay.net/college-paper agency of all the times where you can buy your tasks. Authors, who work there, will ensure that your order will be done in time and at the highest level of their professionalism!!!

    ReplyDelete
  5. Hey! I am so thankful for the information about how to determine the direction of scroll using AngularJS, as it is exactly what I was looking for! Who can do my assignments online? I would like to say thanks to this term paper writing service, that my schoolmate adviced me, and to authors, who work there, for their quick reply and great patience. My master is always crazy about requirements and he needed everything to be at high level to get the highest mark. After using this online agency I've got my first “A” mark and, I think, not the last in this learning year.

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts