一.介紹
Element.scrollIntoView() 方法讓當前的元素滾動到瀏覽器窗口的可視區域內。
-
調用方法為 element.scrollIntoView() 參數默認為 true。
-
參數為 true時調用該函數,頁面(或容器)發生滾動,使element的頂部與視圖(容器)頂部對齊;
-
參數為 false時,使element的底部與視圖(容器)底部對齊。
-
-
TIPS:頁面(容器)可滾動時才有用!
二.兼容性
三.使用
-
<p id= "pToShow">The para to show</p>
-
-
document.getElementById( "pToShow").scrollIntoView();(document.getElementById("pToShow").scrollIntoView(true);) 滾動到頂部
-
document.getElementById( "pToShow").scrollIntoView(false);滾動到底部
例如移動端引用: