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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ results

npm-debug.log
node_modules

.idea
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,30 @@ Length of time, in milliseconds, the animation will take.
Default value: `html, body`

The container element to scroll.

## Config

You can globally configure the options by using the scrollToConfigProvider:

```
(function () {
'use strict';

angular.module('app.core')
.config(configure);

/* @ngInject */
function configure(scrollToConfigProvider) {
scrollToConfigProvider.config.offset = 80;
scrollToConfigProvider.config.duration = 200;
scrollToConfigProvider.config.container = 'body';
}
})();
```

### [UPDATED 2014-05-21] Included hook allow the scrolling action to be triggered from a controller

Added a `triggerScroll(delay)` function that will trigger the scroll action after an optional delay (in milliseconds)



54 changes: 32 additions & 22 deletions angular-scrollto.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
angular.module('scrollto', []);
(function () {
'use strict';

angular.module('scrollto', [])
.provider('scrollToConfig', scrollToConfig)
.directive('scrollTo', scrollTo);

function scrollToConfig() {
this.config = {container: 'html, body', offset: 0, duration: 150};
this.$get = function () { return {config: this.config}; };
}

scrollTo.$inject = ['$timeout', 'scrollToConfig'];

function scrollTo($timeout, scrollToConfig) {
return {restrict: 'A', link: link};

function link(scope, element, attrs) {
var settings = angular.extend(
{scrollTo: angular.element(), easing: 'swing'},
scrollToConfig.config, attrs);
element.on('click', function () { $timeout(scroll(settings)); });

// Hook to trigger the scrolling action outside of the target element (e.g. can call from a Controller)
scope.triggerScroll = function(delay) {
delay = delay || 0; // delay is optional
$timeout(scroll(settings), delay);
};
}

angular.module('scrollto')
.directive('scrollTo', ['$timeout', function ($timeout) {

function scroll (settings) {
return function () {
var scrollPane = angular.element(settings.container);
var scrollTo = (typeof settings.scrollTo == "number") ? settings.scrollTo : angular.element(settings.scrollTo);
if (typeof scrollTo.offset() == 'undefined') { return; } // element no longer available
var scrollY = (typeof scrollTo == "number") ? scrollTo : scrollTo.offset().top - settings.offset;
scrollPane.animate({scrollTop : scrollY }, settings.duration, settings.easing, function(){
if (typeof callback == 'function') { callback.call(this); }
});
}
}

return {
restrict: 'A',
link: function (scope, element, attrs) {
var settings = angular.extend({
container: 'html, body',
scrollTo: angular.element(),
offset: 0,
duration: 150,
easing: 'swing'
}, attrs);

element.on('click', function () {
$timeout(scroll(settings));
});
}
};
}]);
}
})();
2 changes: 1 addition & 1 deletion angular-scrollto.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "angular-scrollto",
"version": "0.1.4",
"homepage": "https://github.com/scottcorgan/angular-scrollto",
"version": "0.1.9",
"homepage": "https://github.com/mkirchstein/angular-scrollto",
"authors": [
"Scott Corgan <scottcorgan@gmail.com>"
"Scott Corgan <scottcorgan@gmail.com>",
"Matt Kirchstein <mkirchstein@gmail.com>",
"Dieter Geerts <dieter@dworks.be>"
],
"description": "Angular directive to scroll to element by selector",
"main": "angular-scrollto.js",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "angular-scrollto",
"version": "0.1.4",
"version": "0.1.9",
"description": "Angular directive to scroll to element by selector",
"main": "angular-scrollto.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/scottcorgan/angular-scrollto.git"
"url": "https://github.com/mkirchstein/angular-scrollto.git"
},
"keywords": [
"angular",
"scroll",
"directive"
],
"author": "Scott Corgan",
"author": "Scott Corgan, Matt Kirchstein, Dieter Geerts",
"license": "MIT",
"bugs": {
"url": "https://github.com/scottcorgan/angular-scrollto/issues"
"url": "https://github.com/mkirchstein/angular-scrollto/issues"
},
"devDependencies": {
"grunt": "~0.4.2",
Expand Down