Skip to content

Commit

Permalink
Merge branch 'cancel-on-scroll'
Browse files Browse the repository at this point in the history
Closes #49
  • Loading branch information
oblador committed Jul 9, 2014
2 parents 68a9ab4 + dd39f3b commit 4b90f5b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,28 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) {
deltaTop = Math.round(top - startTop);

var startTime = null;
var el = this;

var cancelOnEvents = 'scroll mousedown mousewheel touchmove keydown';
var cancelScrollAnimation = function($event) {
if (!$event || $event.which > 0) {
el.unbind(cancelOnEvents, cancelScrollAnimation);
cancelAnimation(scrollAnimation);
deferred.reject();
scrollAnimation = null;
}
};

if(scrollAnimation) {
cancelAnimation(scrollAnimation);
deferred.reject();
cancelScrollAnimation();
}
var el = this;
deferred = $q.defer();

if(!deltaLeft && !deltaTop) {
deferred.resolve();
return deferred.promise;
}

var cancelOnScroll = function() {
cancelAnimation(scrollAnimation);
deferred.reject();
};

var animationStep = function(timestamp) {
if (startTime === null) {
startTime = timestamp;
Expand All @@ -78,15 +83,16 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) {
if(percent < 1) {
scrollAnimation = requestAnimation(animationStep);
} else {
angular.element($window).unbind('mousewheel', cancelOnScroll);
el.unbind(cancelOnEvents, cancelScrollAnimation);
scrollAnimation = null;
deferred.resolve();
}
};

//Fix random mobile safari bug when scrolling to top by hitting status bar
el.scrollTo(startLeft, startTop);
angular.element($window).bind('mousewheel', cancelOnScroll);

el.bind(cancelOnEvents, cancelScrollAnimation);

scrollAnimation = requestAnimation(animationStep);
return deferred.promise;
Expand Down

0 comments on commit 4b90f5b

Please sign in to comment.