Created
July 24, 2013 03:31
-
-
Save lanqy/6067881 to your computer and use it in GitHub Desktop.
Lazy Function Definition Pattern
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
| //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