Skip to content

Commit

Permalink
Made duScrollspy events prefixed/more sensibly named and added docume…
Browse files Browse the repository at this point in the history
…ntation.
  • Loading branch information
oblador committed Mar 11, 2014
1 parent ce92a77 commit c133e8a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ To change the default duration:
angular.module('myApp', ['duScroll']).value('duScrollDuration', 5000);
```

### Scroll spy events

The `duScrollspy` directive fires the global events `duScrollspy:becameActive` and `duScrollspy:becameInactive` with an angular.element wrapped element as first argument. This is nice to have if you want the URL bar to reflect where on the page the visitor are, like this:

```js
angular.module('myApp', ['duScroll']).
config(function($locationProvider) {
$locationProvider.html5Mode(true);
}).
run(function($rootScope, $location){
$rootScope.$on('duScrollspy:becameActive', function($event, $element){
//Automaticly update location
var hash = $element.prop('hash');
if(hash) {
$location.hash(hash.substr(1)).replace();
$rootScope.$apply();
}
});
});
```

Building
--------

Expand Down
4 changes: 2 additions & 2 deletions src/directives/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ directive('duScrollspy', function($rootScope, scrollPosition) {
if(currentlyActive === toBeActive) return;
if(currentlyActive) {
currentlyActive.$element.removeClass('active');
$rootScope.$broadcast('inactive', currentlyActive.$element);
$rootScope.$broadcast('duScrollspy:becameInactive', currentlyActive.$element);
}
if(toBeActive) {
toBeActive.$element.addClass('active');
$rootScope.$broadcast('active', toBeActive.$element);
$rootScope.$broadcast('duScrollspy:becameActive', toBeActive.$element);
}
currentlyActive = toBeActive;
}
Expand Down

0 comments on commit c133e8a

Please sign in to comment.