Created
November 24, 2022 09:20
-
-
Save tcdw/1cc937eb5697e745819325082b5cd6ab to your computer and use it in GitHub Desktop.
让 IE9+ 兼容 window.scrollX 和 window.scrollY,不需要改写已有代码
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
if (typeof window.scrollX !== "number" || typeof window.scrollY !== "number") { | |
Object.defineProperty(window, "scrollX", { | |
get() { | |
return window.pageXOffset; | |
} | |
}); | |
Object.defineProperty(window, "scrollY", { | |
get() { | |
return window.pageYOffset; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment