Skip to content

Instantly share code, notes, and snippets.

@goldhand
Last active August 29, 2015 14:14
Show Gist options
  • Save goldhand/9ef6ffd240d7acf880ec to your computer and use it in GitHub Desktop.
Save goldhand/9ef6ffd240d7acf880ec to your computer and use it in GitHub Desktop.
messing with scrolling in angularjs
$rootScope.scrollLevel = {
'one': false,
'two': false,
};
$rootScope.scrollY = window.pageYOffset;
$rootScope.scrollingDown = false;
$rootScope.scrollingUp = false
window.onscroll = function () {
if($rootScope.scrollY>window.pageYOffset){
$rootScope.scrollingDown = false;
$rootScope.scrollingUp = true;
};
if($rootScope.scrollY<window.pageYOffset){
$rootScope.scrollingDown = true;
$rootScope.scrollingUp = false;
};
$rootScope.scrollY = window.pageYOffset;
// any $scope variable updates
if($rootScope.scrollY<=64) {
$rootScope.scrollLevel.one=false;
};
if($rootScope.scrollY>64) {
$rootScope.scrollLevel.one=true;
};
if($rootScope.scrollY>128) {
$rootScope.scrollLevel.two=true;
};
if($rootScope.scrollY<=128) {
$rootScope.scrollLevel.two=false;
};
$scope.$digest();
};
$scope.$on('$destroy', function() {
window.onscroll = null;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment