From 23040b49894786c2ad413cb6d161ee475612a954 Mon Sep 17 00:00:00 2001 From: Sten Muchow Date: Mon, 7 Dec 2015 14:32:00 +0000 Subject: [PATCH 1/2] Added a scroll if check on the scrollTo directive We now have the abiliity to check if a scroll should be made or not based on a certain criteria. --- lib/angular-smooth-scroll.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/angular-smooth-scroll.js b/lib/angular-smooth-scroll.js index df0c269..4730b7b 100644 --- a/lib/angular-smooth-scroll.js +++ b/lib/angular-smooth-scroll.js @@ -225,6 +225,7 @@ scope: { callbackBefore: '&', callbackAfter: '&', + scrollIf: '&' }, link: function($scope, $elem, $attrs) { var targetElement; @@ -252,15 +253,19 @@ } } }; - - smoothScroll(targetElement, { - duration: $attrs.duration, - offset: $attrs.offset, - easing: $attrs.easing, - callbackBefore: callbackBefore, - callbackAfter: callbackAfter, - containerId: $attrs.containerId - }); + + var shouldScroll = $attrs.scrollIf ? $scope.scrollIf() : true; + + if(shouldScroll) { + smoothScroll(targetElement, { + duration: $attrs.duration, + offset: $attrs.offset, + easing: $attrs.easing, + callbackBefore: callbackBefore, + callbackAfter: callbackAfter, + containerId: $attrs.containerId + }); + } return false; }); @@ -268,4 +273,4 @@ }; }]); -}()); \ No newline at end of file +}()); From fb2fabdb593e6abbdd15d8338f620f3ccc24f713 Mon Sep 17 00:00:00 2001 From: Sten Muchow Date: Fri, 18 Dec 2015 08:19:13 -0600 Subject: [PATCH 2/2] Added info for scrollIf option to the scrollTo directive Updated the readme to include usage instructions for the scrollIf truthy check, as to allow the scroll to fire or not. --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fe56e97..2be54f6 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Example: