Created
October 25, 2013 01:22
-
-
Save snichme/7148054 to your computer and use it in GitHub Desktop.
Scroller service for Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| 'use strict'; | |
| angular.module('ngExtensionsApp') | |
| .factory('Scroll', function($window, $timeout) { | |
| var wait = 100, | |
| callbacks = [], | |
| timeout_identifier = null; | |
| function onScroll(event) { | |
| $timeout.cancel(timeout_identifier); | |
| timeout_identifier = $timeout(function() { | |
| callbacks.forEach(function(cb) { | |
| cb(event); | |
| }); | |
| }, wait); | |
| }; | |
| $window.onscroll = onScroll; | |
| return function(cb) { | |
| callbacks.push(cb); | |
| }; | |
| }); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment