Skip to content

Instantly share code, notes, and snippets.

@tcdw
Created November 24, 2022 09:20
Show Gist options
  • Save tcdw/1cc937eb5697e745819325082b5cd6ab to your computer and use it in GitHub Desktop.
Save tcdw/1cc937eb5697e745819325082b5cd6ab to your computer and use it in GitHub Desktop.
让 IE9+ 兼容 window.scrollX 和 window.scrollY,不需要改写已有代码
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