Skip to content

Add duScrollDelay option for smoothScroll directive #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<nav>
<ul>
<li><a href="#section-1" du-smooth-scroll du-scrollspy>Section 1</a></li>
<li><a href="#section-2" du-smooth-scroll du-scrollspy>Section 2</a></li>
<li><a href="#section-2" du-smooth-scroll delay="500" du-scrollspy>Section 2</a></li>
<li><a du-smooth-scroll="section-3" du-scrollspy>Section 3</a></li>
<li><a href="http://github.com/oblador/angular-scroll/">Project on Github</a></li>
</ul>
Expand Down
25 changes: 19 additions & 6 deletions src/directives/smooth-scroll.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
});
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down