Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@markcoleman
Created April 3, 2013 11:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markcoleman/5300596 to your computer and use it in GitHub Desktop.
Save markcoleman/5300596 to your computer and use it in GitHub Desktop.
Revised scroll directive that supports IE8 Offset from http://stackoverflow.com/a/10286208/181776 Scroll from http://stackoverflow.com/a/14880862/181776
.directive("scroll", function ($window) {
return function (scope, element, attrs) {
function getScrollOffsets(w) {
// Use the specified window or the current window if no argument
w = w || window;
// This works for all browsers except IE versions 8 and before
if (w.pageXOffset != null) return {
x: w.pageXOffset,
y: w.pageYOffset
};
// For IE (or any browser) in Standards mode
var d = w.document;
if (document.compatMode == "CSS1Compat") {
return {
x: d.documentElement.scrollLeft,
y: d.documentElement.scrollTop
};
}
// For browsers in Quirks mode
return {
x: d.body.scrollLeft,
y: d.body.scrollTop
};
}
angular.element($window).bind("scroll", function () {
var offset = getScrollOffsets($window);
if (offset.y >= 50) {
scope.boolChangeClass = true;
} else {
scope.boolChangeClass = false;
}
scope.$apply();
});
};
})
@caioiglesias
Copy link

will you create a repo out of it?

@caioiglesias
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment