Skip to content
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
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Example:
<button
scroll-to="elem-id5"
duration="1800"
scroll-if="isTruthy()"
callback-before="aFunction(element)"
callback-after="anotherFunction">
Scroll to next page.
Expand Down Expand Up @@ -185,20 +186,20 @@ The offset from the top of the page in which the scroll should stop.
type: `string`
default: `easeInOutQuart`

the easing function to be used for this scroll.
The easing function to be used for this scroll.

#### callbackBefore
type: `function`
default: `function(element) {}`

a callback function to run before the scroll has started. It is passed the
A callback function to run before the scroll has started. It is passed the
element that will be scrolled to.

#### callbackAfter
type: `function`
default: `function(element) {}`

a callback function to run after the scroll has completed. It is passed the
A callback function to run after the scroll has completed. It is passed the
element that was scrolled to.

#### containerId
Expand All @@ -207,6 +208,12 @@ default: null

ID of the scrollable container which the element is a child of.

#### scrollIf
type: `function`, `boolean`, `string`, `number`
default: true

Will allow scrolling if the value passed to scrollIf resolves to a truthy value.

### Easing functions

The available easing functions are:
Expand Down
25 changes: 15 additions & 10 deletions lib/angular-smooth-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
scope: {
callbackBefore: '&',
callbackAfter: '&',
scrollIf: '&'
},
link: function($scope, $elem, $attrs) {
var targetElement;
Expand Down Expand Up @@ -252,20 +253,24 @@
}
}
};

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;
});
}
};
}]);

}());
}());