Document: scrollingElement property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.

Thuộc tính chỉ đọc scrollingElement của giao diện Document trả về tham chiếu đến Element cuộn tài liệu. Ở chế độ chuẩn, đây là phần tử gốc của tài liệu, document.documentElement.

Khi ở chế độ quirks, thuộc tính scrollingElement trả về phần tử HTML body nếu nó tồn tại và không có khả năng cuộn, ngược lại trả về null. Điều này có vẻ đáng ngạc nhiên nhưng đúng theo cả đặc tả và trình duyệt.

Giá trị

Element cuộn tài liệu, thường là phần tử gốc (trừ khi không ở chế độ chuẩn).

Ví dụ

js
const scrollElm = document.scrollingElement;
scrollElm.scrollTop = 0;

Đặc tả kỹ thuật

Specification
CSSOM View Module
# dom-document-scrollingelement

Tương thích trình duyệt