HTML DOMscrollIntoViewメソッド
例
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
}