Created
April 3, 2013 11:59
-
-
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
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
.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(); | |
}); | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've set it up here https://github.com/caioiglesias/scroll-animate-directive