HTML DOM scrollIntoView Method
ตัวอย่าง
เลื่อนองค์ประกอบด้วย id="content" ไปยังพื้นที่ที่มองเห็นได้ของหน้าต่างเบราว์เซอร์:
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
scrollIntoView() วิธีการเลื่อนองค์ประกอบที่ระบุไปยังพื้นที่ที่มองเห็นได้ของหน้าต่างเบราว์เซอร์
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่รองรับวิธีการนี้อย่างเต็มที่
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
ไวยากรณ์
element.scrollIntoView(alignTo)
พารามิเตอร์
Parameter | Type | Description |
---|---|---|
alignTo | Boolean | Optional. A boolean value that indicates the type of the align:
true - the top of the element will be aligned to the top of the visible area of the scrollable ancestor false - the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. If omitted, it will scroll to the top of the element. Note: Depending on the layout of other elements, some elements may not be scrolled completely to the top or to the bottom. |
รายละเอียดทางเทคนิค
คืนมูลค่า: | ไม่มีค่าส่งคืน |
---|---|
เวอร์ชัน DOM | ทดลอง |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
เลื่อนไปที่ด้านบนหรือด้านล่างขององค์ประกอบ:
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}