From f617a9d181953354057879e0e54fa0a4e0aa6169 Mon Sep 17 00:00:00 2001 From: Daniel Karlsson Date: Thu, 16 Jul 2015 18:31:47 +0200 Subject: [PATCH] Added hasBouncing alternative to ionSlideBox. --- js/angular/directive/slideBox.js | 5 ++++- js/views/sliderView.js | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/js/angular/directive/slideBox.js b/js/angular/directive/slideBox.js index 2c7fba28bb0..9d4936a952c 100644 --- a/js/angular/directive/slideBox.js +++ b/js/angular/directive/slideBox.js @@ -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; @@ -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(); diff --git a/js/views/sliderView.js b/js/views/sliderView.js index c6d4277bcd9..6b8212ca5ab 100644 --- a/js/views/sliderView.js +++ b/js/views/sliderView.js @@ -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);