Skip to content

Commit f617a9d

Browse files
Daniel Karlssonmlynch
Daniel Karlsson
authored andcommitted
Added hasBouncing alternative to ionSlideBox.
1 parent b368671 commit f617a9d

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Diff for: js/angular/directive/slideBox.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
5555
pagerClick: '&',
5656
disableScroll: '@',
5757
onSlideChanged: '&',
58-
activeSlide: '=?'
58+
activeSlide: '=?',
59+
hasBouncing: '@'
5960
},
6061
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
6162
var _this = this;
6263

6364
var continuous = $scope.$eval($scope.doesContinue) === true;
65+
var bouncing = ($scope.$eval($scope.hasBouncing) !== false); //Default to true
6466
var shouldAutoPlay = isDefined($attrs.autoPlay) ? !!$scope.autoPlay : false;
6567
var slideInterval = shouldAutoPlay ? $scope.$eval($scope.slideInterval) || 4000 : 0;
6668

@@ -69,6 +71,7 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
6971
auto: slideInterval,
7072
continuous: continuous,
7173
startSlide: $scope.activeSlide,
74+
bouncing: bouncing,
7275
slidesChanged: function() {
7376
$scope.currentSlide = slider.currentIndex();
7477

Diff for: js/views/sliderView.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,23 @@ ionic.views.Slider = ionic.views.View.inherit({
379379
translate(index, delta.x + slidePos[index], 0);
380380
translate(circle(index + 1), delta.x + slidePos[circle(index + 1)], 0);
381381

382-
} else {
383-
384-
delta.x =
385-
delta.x /
386-
( (!index && delta.x > 0 || // if first slide and sliding left
387-
index == slides.length - 1 && // or if last slide and sliding right
388-
delta.x < 0 // and if sliding at all
389-
) ?
390-
( Math.abs(delta.x) / width + 1 ) // determine resistance level
391-
: 1 ); // no resistance if false
382+
} if(options.bouncing){
383+
delta.x =
384+
delta.x /
385+
( (!index && delta.x > 0 || // if first slide and sliding left
386+
index == slides.length - 1 && // or if last slide and sliding right
387+
delta.x < 0 // and if sliding at all
388+
) ?
389+
( Math.abs(delta.x) / width + 1 ) // determine resistance level
390+
: 1 ); // no resistance if false
391+
} else {
392+
if(width*index-delta.x < 0) { //We are trying scroll past left boundary
393+
delta.x = Math.min(delta.x, width*index) //Set delta.x so we don't go past left screen
394+
}
395+
if(Math.abs(delta.x) > width*(slides.length-index-1)){ //We are trying to scroll past right bondary
396+
delta.x = Math.max(-width*(slides.length-index-1), delta.x) //Set delta.x so we don't go past right screen
397+
}
398+
} // no resistance if false
392399

393400
// translate 1:1
394401
translate(index - 1, delta.x + slidePos[index - 1], 0);

0 commit comments

Comments
 (0)