LoginSignup
0
2

More than 5 years have passed since last update.

textarea のスクロールのパーセンテージが知りたい

Posted at

textarea のスクロールのパーセンテージが知りたい

textarea を最大までスクロールしたとき、次の関係が成り立つ。

const t = $("textarea#foo")[0];

t.scrollHeight - t.offsetHeight === t.scrollTop;

故に現在のスクロール位置は

$(t).on("scroll", (ev)=>{
    const ratio = t.scrollTop / ( t.scrollHeight - t.offsetHeight );
    console.log(ratio * 100, "%");
});
0
2
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
2