Skip to content

Commit f847c20

Browse files
deflomuajoslin
authored andcommitted
feat($ionicScrollDelegate): add scrollBy(left,top,animate) to delegate
Closes #987
1 parent 9a49129 commit f847c20

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

js/ext/angular/src/controller/ionicScrollController.js

+14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ angular.module('ionic.ui.scroll')
8686
* @param {boolean=} shouldAnimate Whether the scroll should animate.
8787
*/
8888
'scrollTo',
89+
/**
90+
* @ngdoc method
91+
* @name $ionicScrollDelegate#scrollBy
92+
* @param {number} left The x-offset to scroll by.
93+
* @param {number} top The y-offset to scroll by.
94+
* @param {boolean=} shouldAnimate Whether the scroll should animate.
95+
*/
96+
'scrollBy',
8997
/**
9098
* @ngdoc method
9199
* @name $ionicScrollDelegate#anchorScroll
@@ -287,6 +295,12 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
287295
});
288296
};
289297

298+
this.scrollBy = function(left, top, shouldAnimate) {
299+
this.resize().then(function() {
300+
scrollView.scrollBy(left, top, !!shouldAnimate);
301+
});
302+
};
303+
290304
this.anchorScroll = function(shouldAnimate) {
291305
this.resize().then(function() {
292306
var hash = $location.hash();

js/ext/angular/test/controller/ionicScrollController.unit.js

+5
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ describe('$ionicScroll Controller', function() {
257257
ctrl.scrollTo(1, 2, shouldAnimate);
258258
expect(ctrl.scrollView.scrollTo).toHaveBeenCalledWith(1, 2, shouldAnimate);
259259
});
260+
it('.scrollBy', function() {
261+
spyOn(ctrl.scrollView, 'scrollBy');
262+
ctrl.scrollBy(1, 2, shouldAnimate);
263+
expect(ctrl.scrollView.scrollBy).toHaveBeenCalledWith(1, 2, shouldAnimate);
264+
});
260265
it('.anchorScroll without hash should scrollTop', inject(function($location, $document) {
261266
$document[0].getElementById = jasmine.createSpy();
262267
$location.hash = function() { return null; };

js/views/scrollView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
13131313
* Scroll by the given offset
13141314
*
13151315
* @param left {Number} Scroll x-axis by given offset
1316-
* @param top {Number} Scroll x-axis by given offset
1316+
* @param top {Number} Scroll y-axis by given offset
13171317
* @param animate {Boolean} Whether to animate the given change
13181318
*/
13191319
scrollBy: function(left, top, animate) {

0 commit comments

Comments
 (0)