$ionicScrollDelegate

Delegate for controlling scrollViews (created by ionContent and ionScroll directives).

Methods called directly on the $ionicScrollDelegate service will control all scroll views. Use the $getByHandle method to control specific scrollViews.

Usage

<body ng-controller="MainCtrl">
  <ion-content>
    <button ng-click="scrollTop()">Scroll to Top!</button>
  </ion-content>
</body>
function MainCtrl($scope, $ionicScrollDelegate) {
  $scope.scrollTop = function() {
    $ionicScrollDelegate.scrollTop();
  };
}

Example of advanced usage, with two scroll areas using delegate-handle for fine control.

<body ng-controller="MainCtrl">
  <ion-content delegate-handle="mainScroll">
    <button ng-click="scrollMainToTop()">
      Scroll content to top!
    </button>
    <ion-scroll delegate-handle="small" style="height: 100px;">
      <button ng-click="scrollSmallToTop()">
        Scroll small area to top!
      </button>
    </ion-scroll>
  </ion-content>
</body>
function MainCtrl($scope, $ionicScrollDelegate) {
  $scope.scrollMainToTop = function() {
    $ionicScrollDelegate.$getByHandle('mainScroll').scrollTop();
  };
  $scope.scrollSmallToTop = function() {
    $ionicScrollDelegate.$getByHandle('small').scrollTop();
  };
}

Methods

resize()

Tell the scrollView to recalculate the size of its container.

scrollTop([shouldAnimate])

Param Type Details
shouldAnimate
(optional)
boolean

Whether the scroll should animate.

scrollBottom([shouldAnimate])

Param Type Details
shouldAnimate
(optional)
boolean

Whether the scroll should animate.

scrollTo(left, top, [shouldAnimate])

Param Type Details
left number

The x-value to scroll to.

top number

The y-value to scroll to.

shouldAnimate
(optional)
boolean

Whether the scroll should animate.

scrollBy(left, top, [shouldAnimate])

Param Type Details
left number

The x-offset to scroll by.

top number

The y-offset to scroll by.

shouldAnimate
(optional)
boolean

Whether the scroll should animate.

zoomTo(level, [animate], [originLeft], [originTop])

Param Type Details
level number

Level to zoom to.

animate
(optional)
boolean

Whether to animate the zoom.

originLeft
(optional)
number

Zoom in at given left coordinate.

originTop
(optional)
number

Zoom in at given top coordinate.

zoomBy(factor, [animate], [originLeft], [originTop])

Param Type Details
factor number

The factor to zoom by.

animate
(optional)
boolean

Whether to animate the zoom.

originLeft
(optional)
number

Zoom in at given left coordinate.

originTop
(optional)
number

Zoom in at given top coordinate.

getScrollPosition()

  • Returns: object The scroll position of this view, with the following properties:
  • {number} left The distance the user has scrolled from the left (starts at 0).
  • {number} top The distance the user has scrolled from the top (starts at 0).
  • {number} zoom The current zoom level.

anchorScroll([shouldAnimate])

Tell the scrollView to scroll to the element with an id matching window.location.hash.

If no matching element is found, it will scroll to top.

Param Type Details
shouldAnimate
(optional)
boolean

Whether the scroll should animate.

freezeScroll([shouldFreeze])

Does not allow this scroll view to scroll either x or y.

Param Type Details
shouldFreeze
(optional)
boolean

Should this scroll view be prevented from scrolling or not.

  • Returns: boolean If the scroll view is being prevented from scrolling or not.

freezeAllScrolls([shouldFreeze])

Does not allow any of the app’s scroll views to scroll either x or y.

Param Type Details
shouldFreeze
(optional)
boolean

Should all app scrolls be prevented from scrolling or not.

getScrollView()

  • Returns: object The scrollView associated with this delegate.

$getByHandle(handle)

Param Type Details
handle string
  • Returns: delegateInstance A delegate instance that controls only the scrollViews with delegate-handle matching the given handle.

Example: $ionicScrollDelegate.$getByHandle('my-handle').scrollTop();