Skip to content

Commit

Permalink
Slidebox bouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Dec 6, 2015
1 parent 96ef1cc commit 465d98c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions js/angular/directive/slideBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
disableScroll: '@',
onSlideChanged: '&',
activeSlide: '=?',
hasBouncing: '@'
bounce: '@'
},
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 bouncing = ($scope.$eval($scope.bounce) !== false); //Default to true
var shouldAutoPlay = isDefined($attrs.autoPlay) ? !!$scope.autoPlay : false;
var slideInterval = shouldAutoPlay ? $scope.$eval($scope.slideInterval) || 4000 : 0;

Expand Down Expand Up @@ -142,7 +142,6 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll
};

this.onPagerClick = function(index) {
console.log('pagerClick', index);
$scope.pagerClick({index: index});
};

Expand Down
21 changes: 11 additions & 10 deletions js/views/sliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,17 @@ 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{
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 the slider bounces, do the bounce!
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
Expand Down
1 change: 0 additions & 1 deletion test/html/slideBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
on-slide-changed="slideChanged(index)"
show-pager="{{$root.showPager}}"
pager-click="pagerClick(index)"
does-continue="true"
auto-play="false">
<ion-slide ng-controller="FirstSlideCtrl">
<h3>Thank you for choosing the Awesome App!</h3>
Expand Down

0 comments on commit 465d98c

Please sign in to comment.