Skip to content

Instantly share code, notes, and snippets.

@lanqy
Created July 24, 2013 03:31
Show Gist options
  • Save lanqy/6067881 to your computer and use it in GitHub Desktop.
Save lanqy/6067881 to your computer and use it in GitHub Desktop.
Lazy Function Definition Pattern
//Lazy Function Definition Pattern
// form http://michaux.ca/articles/lazy-function-definition-pattern
var getScrollY = function () {
if (typeof window.pageYOffset == 'number') {
getScrollY = function () {
return window.pageYOffset;
};
} else if ((typeof document.compatMode == 'string') && (document.compatMode.indexOf('CSS') >= 0) && (document.documentElement) && (typeof document.documentElement.scrollTop == 'number')) {
getScrollY = function () {
return document.documentElement.scrollTop;
};
} else if ((document.body) && (typeof document.body.scrollTop == 'number')) {
getScrollY = function () {
return document.body.scrollTop;
}
} else {
getScrollY = function () {
return NaN;
};
}
return getScrollY();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment