Window.scrollX
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
* Some parts of this feature may have varying levels of support.
返回文档/页面水平方向滚动的像素值。
示例
js
// 如果 scrollX 大于 400,则把文档重新滚动到左上角。
if (window.scrollX > 400) {
window.scroll(0, 0);
}
备注
pageXOffset
属性是 scrollX
属性的别名。这意味这如果你没有为其中的任一属性重新赋值,window.pageXOffset == window.scrollX
总为真。
规范
Specification |
---|
CSSOM View Module # dom-window-scrollx |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scrollX | ||||||||||||
Subpixel precision |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Uses a non-standard name.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.