Skip to content

Commit

Permalink
Added hasBouncing alternative to ionSlideBox.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Karlsson authored and mlynch committed Dec 6, 2015
1 parent b368671 commit f617a9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion js/angular/directive/slideBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
pagerClick: '&',
disableScroll: '@',
onSlideChanged: '&',
activeSlide: '=?'
activeSlide: '=?',
hasBouncing: '@'
},
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
var _this = this;

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

Expand All @@ -69,6 +71,7 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
auto: slideInterval,
continuous: continuous,
startSlide: $scope.activeSlide,
bouncing: bouncing,
slidesChanged: function() {
$scope.currentSlide = slider.currentIndex();

Expand Down
27 changes: 17 additions & 10 deletions js/views/sliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,23 @@ ionic.views.Slider = ionic.views.View.inherit({
translate(index, delta.x + slidePos[index], 0);
translate(circle(index + 1), delta.x + slidePos[circle(index + 1)], 0);

} else {

delta.x =
delta.x /
( (!index && delta.x > 0 || // if first slide and sliding left
index == slides.length - 1 && // or if last slide and sliding right
delta.x < 0 // and if sliding at all
) ?
( Math.abs(delta.x) / width + 1 ) // determine resistance level
: 1 ); // no resistance if false
} if(options.bouncing){
delta.x =
delta.x /
( (!index && delta.x > 0 || // if first slide and sliding left
index == slides.length - 1 && // or if last slide and sliding right
delta.x < 0 // and if sliding at all
) ?
( Math.abs(delta.x) / width + 1 ) // determine resistance level
: 1 ); // no resistance if false
} else {
if(width*index-delta.x < 0) { //We are trying scroll past left boundary
delta.x = Math.min(delta.x, width*index) //Set delta.x so we don't go past left screen
}
if(Math.abs(delta.x) > width*(slides.length-index-1)){ //We are trying to scroll past right bondary
delta.x = Math.max(-width*(slides.length-index-1), delta.x) //Set delta.x so we don't go past right screen
}
} // no resistance if false

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

0 comments on commit f617a9d

Please sign in to comment.