LoginSignup
0
0

More than 3 years have passed since last update.

[JS | jQuery]1行で指定要素までスクロールする

Posted at

1行で指定要素までスクロール

$('#target').get(0).scrollIntoView(true);

jQuery使わないバージョン

document.getElementById('targetElementId').scrollIntoView(true);

使用例

    $(window).on("load",function() { //ページ全体が読み込まれた時に動く
        $('#target').get(0).scrollIntoView({ // スクロール
            behavior: 'smooth' // スムーズに
        });
    });

メモ

jQueryで素のJSの「document.getElementById」と合わせる時は「.get(0)」が必要。

参考:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0