Skip to content

Add scrollBy to $ionicScrollDelegate #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions js/ext/angular/src/controller/ionicScrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ angular.module('ionic.ui.scroll')
* @param {boolean=} shouldAnimate Whether the scroll should animate.
*/
'scrollTo',
/**
* @ngdoc method
* @name $ionicScrollDelegate#scrollBy
* @param {number} left The x-offset to scroll by.
* @param {number} top The y-offset to scroll by.
* @param {boolean=} shouldAnimate Whether the scroll should animate.
*/
'scrollBy',
/**
* @ngdoc method
* @name $ionicScrollDelegate#anchorScroll
Expand Down Expand Up @@ -287,6 +295,12 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
});
};

this.scrollBy = function(left, top, shouldAnimate) {
this.resize().then(function() {
scrollView.scrollBy(left, top, !!shouldAnimate);
});
};

this.anchorScroll = function(shouldAnimate) {
this.resize().then(function() {
var hash = $location.hash();
Expand Down
5 changes: 5 additions & 0 deletions js/ext/angular/test/controller/ionicScrollController.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ describe('$ionicScroll Controller', function() {
ctrl.scrollTo(1, 2, shouldAnimate);
expect(ctrl.scrollView.scrollTo).toHaveBeenCalledWith(1, 2, shouldAnimate);
});
it('.scrollBy', function() {
spyOn(ctrl.scrollView, 'scrollBy');
ctrl.scrollBy(1, 2, shouldAnimate);
expect(ctrl.scrollView.scrollBy).toHaveBeenCalledWith(1, 2, shouldAnimate);
});
it('.anchorScroll without hash should scrollTop', inject(function($location, $document) {
$document[0].getElementById = jasmine.createSpy();
$location.hash = function() { return null; };
Expand Down
2 changes: 1 addition & 1 deletion js/views/scrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
* Scroll by the given offset
*
* @param left {Number} Scroll x-axis by given offset
* @param top {Number} Scroll x-axis by given offset
* @param top {Number} Scroll y-axis by given offset
* @param animate {Boolean} Whether to animate the given change
*/
scrollBy: function(left, top, animate) {
Expand Down