JSFiddle - React, Tailwind, and code Playground

by huuzoo

HTML

<div id="target">
  <div id="sample">
    <p>サンプルテキストサンプルテキストサンプルテキスト<br></p>
   </div>
</div>
<button onclick="countScroll();">スクロール量確認</button>
<div>スクロール量:<span id="output"></span></div>

CSS

#target {
  overflow: scroll; 
  width: 200px;
  height: 70px;
}
#sample {
  width: 200px;
  height: 500px;
  background-color: yellow;
}

JavaScript

function countScroll(){
	var target = document.getElementById('target');
  var y = target.scrollTop;
  document.getElementById('output').innerHTML = y;
}