From 6a931c4da89516e361d6d258989eab2b46259560 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Tue, 8 Jul 2014 21:42:26 +0100 Subject: [PATCH 1/2] Handle other events --- src/helpers.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 582a09f..16a4eb8 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -58,9 +58,13 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { return deferred.promise; } - var cancelOnScroll = function() { - cancelAnimation(scrollAnimation); - deferred.reject(); + var cancelScrollEvents = 'scroll mousedown mousewheel touchmove keydown', + cancelScrollFn = function(event) { + if (event.which > 0) { + angular.element($window).unbind(cancelScrollEvents); + cancelAnimation(scrollAnimation); + deferred.reject(); + } }; var animationStep = function(timestamp) { @@ -78,7 +82,7 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { if(percent < 1) { scrollAnimation = requestAnimation(animationStep); } else { - angular.element($window).unbind('mousewheel', cancelOnScroll); + angular.element($window).unbind(cancelScrollEvents, cancelScrollFn); scrollAnimation = null; deferred.resolve(); } @@ -86,7 +90,7 @@ 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); + angular.element($window).bind(cancelScrollEvents, cancelScrollFn); scrollAnimation = requestAnimation(animationStep); return deferred.promise; From dd39f3bd836edd57ebdfc388eddecbfa2f14f79a Mon Sep 17 00:00:00 2001 From: Joel Arvidsson Date: Wed, 9 Jul 2014 11:35:44 +0200 Subject: [PATCH 2/2] Refactored scroll animation cancelling and made it container specific. --- src/helpers.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 16a4eb8..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,15 +68,6 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { return deferred.promise; } - var cancelScrollEvents = 'scroll mousedown mousewheel touchmove keydown', - cancelScrollFn = function(event) { - if (event.which > 0) { - angular.element($window).unbind(cancelScrollEvents); - cancelAnimation(scrollAnimation); - deferred.reject(); - } - }; - var animationStep = function(timestamp) { if (startTime === null) { startTime = timestamp; @@ -82,7 +83,7 @@ run(function($window, $q, cancelAnimation, requestAnimation, duScrollEasing) { if(percent < 1) { scrollAnimation = requestAnimation(animationStep); } else { - angular.element($window).unbind(cancelScrollEvents, cancelScrollFn); + el.unbind(cancelOnEvents, cancelScrollAnimation); scrollAnimation = null; deferred.resolve(); } @@ -90,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(cancelScrollEvents, cancelScrollFn); + + el.bind(cancelOnEvents, cancelScrollAnimation); scrollAnimation = requestAnimation(animationStep); return deferred.promise;