diff --git a/src/helpers.js b/src/helpers.js index 582a09f..60c64d3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -46,11 +46,21 @@ 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) { @@ -58,11 +68,6 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { return deferred.promise; } - var cancelOnScroll = function() { - cancelAnimation(scrollAnimation); - deferred.reject(); - }; - var animationStep = function(timestamp) { if (startTime === null) { startTime = timestamp; @@ -78,7 +83,7 @@ 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(); } @@ -86,7 +91,8 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { //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;