LoginSignup
66
54

More than 3 years have passed since last update.

JavaScriptでスクロールを最下部に移動する方法

Last updated at Posted at 2017-10-17

説明

JavaScriptで、非同期通信のタイミングに、スクロールを最下部に移動したかったのでメモ。

var obj = document.getElementById(targetId);
obj.scrollTop = obj.scrollHeight;

ページの最下部に移動する場合は以下で可能

var element = document.documentElement;
var bottom = element.scrollHeight - element.clientHeight;
window.scroll(0, bottom);

参考ページ

https://developer.mozilla.org/ja/docs/Web/API/Element/scrollTop
https://syncer.jp/javascript-reference/element/scrollheight

66
54
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
66
54