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

1 comment:

  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

Blogroll

Follow this blog by Email

Popular Posts