diff --git a/example/index.html b/example/index.html index 8fcdea4..e4d89ff 100644 --- a/example/index.html +++ b/example/index.html @@ -78,7 +78,7 @@ Section 1 - Section 2 + Section 2 Section 3 Project on Github diff --git a/src/directives/smooth-scroll.js b/src/directives/smooth-scroll.js index 1283171..be6729d 100644 --- a/src/directives/smooth-scroll.js +++ b/src/directives/smooth-scroll.js @@ -1,9 +1,11 @@ angular.module('duScroll.smoothScroll', ['duScroll.scrollHelpers', 'duScroll.scrollContainerAPI']) -.directive('duSmoothScroll', function(duScrollDuration, duScrollOffset, scrollContainerAPI) { +.directive('duSmoothScroll', function($timeout, duScrollDuration, duScrollDelay, duScrollOffset, scrollContainerAPI) { 'use strict'; return { link : function($scope, $element, $attr) { + var delayTimeout; + $element.on('click', function(e) { if((!$attr.href || $attr.href.indexOf('#') === -1) && $attr.duSmoothScroll === '') return; @@ -17,13 +19,24 @@ angular.module('duScroll.smoothScroll', ['duScroll.scrollHelpers', 'duScroll.scr var offset = $attr.offset ? parseInt($attr.offset, 10) : duScrollOffset; var duration = $attr.duration ? parseInt($attr.duration, 10) : duScrollDuration; + var delay = $attr.delay ? parseInt($attr.delay, 10) : duScrollDelay; var container = scrollContainerAPI.getContainer($scope); - container.duScrollToElement( - angular.element(target), - isNaN(offset) ? 0 : offset, - isNaN(duration) ? 0 : duration - ); + var scrollFn = function() { + container.duScrollToElement( + angular.element(target), + isNaN(offset) ? 0 : offset, + isNaN(duration) ? 0 : duration + ); + } + + if (delay) { + $timeout.cancel(delayTimeout); + delayTimeout = $timeout(scrollFn, delay); + + } else { + scrollFn(); + } }); } }; diff --git a/src/module.js b/src/module.js index 871b978..5534a4b 100644 --- a/src/module.js +++ b/src/module.js @@ -19,6 +19,8 @@ var duScroll = angular.module('duScroll', [ ]) //Default animation duration for smoothScroll directive .value('duScrollDuration', 350) + //Default animation delay for smoothScroll directive + .value('duScrollDelay', 0) //Scrollspy debounce interval, set to 0 to disable .value('duScrollSpyWait', 100) //Wether or not multiple scrollspies can be active at once